• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Nested try/catch but control always goes to outer catch

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
never mind...
it was me who was catching an exception where none was being thrown..
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic