aspose 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 Soft Skills this week in the Jobs Discussion 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