• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception Handling!!!

 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic