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

21st May 2019, 1:18 PM
Tzion
Tzion - avatar
3 Respuestas
+ 2
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
21st May 2019, 1:24 PM
Taste
Taste - avatar
+ 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?
21st May 2019, 1:28 PM
Tzion
Tzion - avatar
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.
21st May 2019, 1:42 PM
Taste
Taste - avatar