• 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 - Exception Subclasses

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings All,

I'm trying to figure out exactly how the catch block flow progresses. In this scenario I want to handle the NamingException and InvalidSearchControlsException (which is a subclass of invalid search controls exception) differently. Therefore, I know that I would put the stricter, subclass exception first. However, my question is, if I then throw the subclass exception in the catch block which catches it, will the next catch block for the higher level exception then catch that exception I just threw?

Any Help Greatly Appreciated,

Eric
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way to test this is to write a small program with some SOP's (System.out.println()). However, to answer your question, afaik the "next catch block" will not catch the exception. You can either wrap the whole thing in another try...catch statement or declare that the method throws the exception.

HTH

Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic