Chris Lacy's Software Engineering Blog

Sunday Feb 01, 2009

Exception Handling

I'm a big fan of the Spring Framework. Their motto, when it comes to exception handling, is: throw unchecked exceptions unless you have a good reason not to (paraphrase). This allows you to place your error handling code at places that make sense, without the clutter of catching or declaring checked exceptions. Throwing unchecked exceptions keeps your code clean, and promotes the good practice of identifying key points within your code where exceptional events may be properly handled, often through a user message and a log action.

It would be nice to add some sort of warning to code that has a high likelihood of throwing an exception, without needing to explicitly handle the exception. For example, declared unchecked exceptions might produce compiler warnings if they are not caught or re-thrown. This would act as a friendly reminder to engineers that they need to account for exceptional conditions, and they might want to add extra error handling around this method if there's something they think they can do.

Another option my be a new class of exceptions that lie between checked and unchecked. Not handling them would produce warnings through the potential call stack.

Comments:

Post a Comment:
Comments are closed for this entry.

Calendar

Feeds

Search

Links

Navigation

Referrers