JAVA exceptions | SoloLearn: Learn to code for FREE!

0

JAVA exceptions

Okay example we got two mistake int b[ ] = new int [ 2 ] try{ int a = 9/0 System.out.println( b[3] ); }catch (ArithmeticException e){ System.out.println("i found the exception"); }catch (Exception e){ System.out.println("Second exception i found!"); } Why the "Second exception i found" doesn't print out? and actually what the functions for having that so much catch actually

5/21/2019 1:18:17 PM

Rael

3 Answers

New Answer

+3

because the error is already caught as arithmetic exception, the second catch will only catch other error that isnt specificallly arithmetic execption or its child class

+1

Taste oh that both mistake is in arithmetic exception? if both is different mistake,so all the catch block will catch the mistake also?

0

sorry i missed the second error, when error occur inside try block its usually terminate the currect flow and move to the flow to catch block that is able to catch the error. the second error basicly never get executed because the flow stop at the first error.