This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Exception Handling!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception Handling!!! " Watch "Exception Handling!!! " New topic
Author

Exception Handling!!!

Mark Henryson
Ranch Hand

Joined: Jul 11, 2005
Posts: 200


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

Joined: Sep 20, 2003
Posts: 1704
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

Joined: Aug 04, 2004
Posts: 724
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.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
 
 
subject: Exception Handling!!!
 
Similar Threads
try, catch question
2 objects EXCEPTION
can anyone answer this problem
doubts on try and finally block
Exception