Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested try/catch but control always goes to outer catch

 
David Requena
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
never mind...
it was me who was catching an exception where none was being thrown..
 
ramya narayanan
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic