Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception Handling - Exception Subclasses

 
Eric Jester
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic