The throw statement
The throw
statement allows the throwing of any exception that a programmer deems necessary. You can even create your own exception. To create a checked exception, extend the java.lang.Exception
class as follows:
class MyCheckedException extends Exception{
public MyCheckedException(String message){
super(message);
}
//add code you need to have here
}
Also, to create an unchecked exception, extend the java.lang.RunitmeException
class, as follows:
class MyUncheckedException extends RuntimeException{
public MyUncheckedException(String message){
super(message);
}
//add code you need to have here
}
Notice the add code you need to have here comment. You can add methods and properties to the custom...