![]() |
VOOZH | about |
Exceptions These are the events that occur due to the programmer error or machine error which causes a disturbance in the normal flow of execution of the program.
Handling Multiple exceptions: There are two methods to handle multiple exceptions in java.
Hierarchy of the exceptions:
👁 ImageDivide by zero: This Program throw Arithmetic exception because of due any number divide by 0 is undefined in Mathematics.
Output:
👁 divideByZeroErrorHandling of Divide by zero exception: Using try-Catch Block
Output:
👁 Divide by zero exception handleMultiple Exceptions (ArithmeticException and IndexoutOfBound Exception)
Output:
👁 ImageExplanation: Here combination of ArrayIndexOutOfBounds and Arithmetic exception occur, but only Arithmetic exception is thrown, Why?
According to the precedence compiler check number[10]=30/0 from right to left. That's why 30/0 to throw ArithmeticException object and the handler of this exception executes Zero cannot divide any number.
Another Method of Multiple Exception: we can combine two Exception using the | operator and either one of them executes according to the exception occurs.