File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Nested try/catch but control always goes to outer catch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Nested try/catch but control always goes to outer catch" Watch "Nested try/catch but control always goes to outer catch" New topic
Author

Nested try/catch but control always goes to outer catch

David Requena
Greenhorn

Joined: Dec 15, 2008
Posts: 2
Hellow,

I have code like the folowing:


Person() constructor espcifies a "throws" clause for NonExistentNotesUserException which in turn is thrown by one of Person's methods calle by the constructor.

NonExistentNotesUserException inherits from DirectoryException.

The thing is: in case of NonExistentNotesUserException being thrown control allways passes to the outer catch caluse instead of the more specific inner one.

Could someone explain what is going on here, please? What would be a better way to acomplish my intent; which is log an error in case o processing a non existent user and proceed to process the next?

TIA
David Requena
Greenhorn

Joined: Dec 15, 2008
Posts: 2
never mind...
it was me who was catching an exception where none was being thrown..
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Dear all,
Here subclassException inherits from superclassException which inturn inherits from Exception.




Now compile & run it

Syntactically it's working fine.

When you comment out this code

in inner try block , only then some compiler-error props up

Apart from that exception is caught in the more - specific inner try block itself.
Hope this will clarify matters.
Regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Nested try/catch but control always goes to outer catch
 
Similar Threads
Runtime.getRuntime().exec() not printing output
returned null;
cant connect after disconnected from ftp server
how to delete an object from heap ?
problem in castor marshallin