0

I have third party libraries being used in my application and I don't know what exceptions they can throw, obviously from debugging and use I can work out some of them but not all.

So, is there a way to know what Exceptions could be thrown without documentation?

Failing that, I know I can catch (Exception) even though most guidelines recommend against that but if I don't catch them will they just bubble up through to the top exception handler? Is there any reason why they wouldn't be able to be handled in this way?

Firedragon
  • 3,685
  • 3
  • 35
  • 75
  • where did you read those guidelines telling you to do not catch exceptions? You _should_ catch exceptions in general or you should prevent them to happen, log them, respond/handle them and so on... definition of reccommend against is generic and not purely true when so vague.... – Davide Piras Dec 05 '11 at 15:56
  • Same discussion: http://stackoverflow.com/questions/8382973/is-catch-throw-a-bad-practice – Gert Arnold Dec 05 '11 at 15:57
  • 1
    @DavidePiras Reading a lot of web searches I have come to the conclusion that if you can handle exceptions then you should. If you cannot then they should bubble up. What I meant above is that catching on the class `Exception` should be avoided but I cannot see anyway to not do this if you don't know what exceptiosn are being thrown – Firedragon Dec 05 '11 at 15:59

1 Answers1

4

Without documentation from the third-party library, there's no way of knowing exactly what Exceptions will be thrown.

Any un-caught Exceptions in your code (like you mention) will bubble up to the top handler. I wouldn't suggest blanket catching all Exceptions though (unless it is a top level logger or something similar). You should really only be handling Exceptions that you can recover from.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
  • Thanks for the comment. I think the team's opinion is to catch all exceptions from the 3rd party and log when they happen then ignore them. Not sure I agreed with tha so wanted to tey and get ideas of other handling strategys. – Firedragon Dec 06 '11 at 08:18