Are you handling all your exceptions?

Exception handling can be quite a tricky subject. How many and which exceptions do you handle and where? But whatever your exception handling strategy is you first need to know exactly what kind of exceptions can to be thrown in the first place.

In Java there is a rule that every function must either catch or declare every possible exception. The result is that a function declaration actually shows the possible exceptions. If that is a good or bad thing is open for discussion, personally I think it just creates a lot of extra work, but it does give some useful insight when deciding which exceptions to catch.

In the .NET world there is no such requirement and the result is that it is a lot harder to see what kind of exceptions might be thrown. And this is especially true when it comes down to the .NET framework code we cannot see (yet).

RedGate saw this as a problem and created a nice utility for tracking down the possible unhandled exceptions in your application. Basically the tool just opens your code, checks all the code that could possibly be executed and reports on any thrown exception that isn’t caught. Of course this doesn’t solve the complete exception management problem but does offer a good starting point in knowing exactly what exceptions could be thrown. See for more details.


2 thoughts on “Are you handling all your exceptions?

Leave a Reply

Your email address will not be published. Required fields are marked *