How can I create a new Exception different from the pre-made types?
public class InvalidBankFeeAmountException extends Exception{
public InvalidBankFeeAmountException(String message){
super(message);
}
}
It will show the warning for the InvalidBankFeeAmountException which is written in the first line.
All you need to do is create a new
classand have itextend Exception.If you want an
Exceptionthat is unchecked, you need toextend RuntimeException.Note: A checked
Exceptionis one that requires you to either surround theExceptionin atry/catchblock or have a ‘throws‘ clause on the method declaration. (likeIOException) UncheckedExceptionsmay be thrown just like checkedExceptions, but you aren’t required to explicitly handle them in any way (IndexOutOfBoundsException).For example: