Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling!!!

 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the above coding, why the ArrayIndexOutOfBoundsException is not invoking. Only the ArithmeticException is called. Why???

output:
--------
java.lang.ArithmeticException: / by zero
After Catch Statement

What happened to ArrayIndexOutOfBoundsException
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Henryson:


In the above coding, why the ArrayIndexOutOfBoundsException is not invoking. Only the ArithmeticException is called. Why???

output:
--------
java.lang.ArithmeticException: / by zero
After Catch Statement

What happened to ArrayIndexOutOfBoundsException


Thats because in above code the ArithmeticException occurs before the code reaches to ArrayIndexOutOfBoundsException. I mean as the ArithmeticException occured at line: a = 42/d; the remaining code wont be executed and directly goes into catch(ArithmeticException e){} block. Hope you understood.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because arithmetic exception is first exception, after this exception the flow continues in catch(ArithmeticException e) block. The code c[40] = 99; is never reached in this case.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic