-3

in Java If we want to create our own custom exception, which keyword should we use?

throw or throws or try & catch?

saboor
  • 23
  • 3

1 Answers1

1

You need to create a new class that extends the class Exception. Throws keyword is used to indicate that the current class propagate exceptions, throw keyword is used to launch the propagation and try catch determined a block where the exception is captured.

 public class MyClass extend Exception {
         public MyClass(String msg)
             super(msg);
}
J.del Rey
  • 103
  • 4