how i can handle multiple exceptions from number of different methods using only one try-catch block in java?

Your program throws only ArithmeticException exception, because of the method call obj.divide();.

The flow of you program is interrupted by this exception and it falls in the catch block. The methods after obj.divide(); are not called that means the ArrayIndexOutOfBoundsException will never been thrown with your inputs.

If you want to test the ArrayIndexOutOfBoundsException comment the first method call.

In general, I can’t think of a scenario that you can throw more than one exception within the same try block

Leave a Comment