I've created my own exception to handle situations like arithmetic exceptions, and other situation involving mathematic rules. But When I call it never goes to my Exception for example,on division by zero goes to arithmetic exception instead
Division by zero and other "standard" arithmetic errors are handled by the runtime or the class library, which don't know about your user defined exception. You can only use your own exceptions in your own code by explcitly throw
ing them when it is appropriate.
Of course, it is possible to catch any arithmetic exceptions thrown by the class library and wrap them into your own exceptions:
try {
...
} catch (java.lang.ArithmeticException exc) {
throw new MyException("An arithmetic error occurred", exc);
}
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