I have problem in exception.getMessage() method when raised for NullPointerException which returns null.
How can I overwrite base Exception.getMessage() to control it without changing in JRE?
Try :
public class MyException extends Exception {
public MyException(String message) {
super(message);
}
public MyException(Throwable throwable) {
super(throwable);
}
public MyException(String message, Throwable throwable) {
super(message, throwable);
}
}
Throw MyException one program.
try {
} catch (NullPointerException e) {
throw new MyException("My exception message", e);
or
throw new MyException("My exception message");
or
throw new MyException(e);
}
Catch MyException another program.
try {
} catch (MyException e) {
System.out.println(e.getMessage());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With