File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Exception Handling - Exception Subclasses Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception Handling - Exception Subclasses" Watch "Exception Handling - Exception Subclasses" New topic

Exception Handling - Exception Subclasses

Eric Jester

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,

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.



Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Exception Handling - Exception Subclasses
jQuery in Action, 3rd edition