This week's giveaways are in the MongoDB and Jobs Discussion forums.
We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Exception Handling - Exception Subclasses Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Exception Handling - Exception Subclasses" Watch "Exception Handling - Exception Subclasses" New topic
Author

Exception Handling - Exception Subclasses

Eric Jester
Greenhorn

Joined: Dec 02, 2004
Posts: 1
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

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception Handling - Exception Subclasses
 
Similar Threads
My interview questions
Catching exception not thrown in try clause
Round Up question re exception& arg type
Exceptions question
Q on Exception Handling