Exceptions for action

Exception design for efficient error handling

Exceptions in object-oriented applications tend to proliferate, overload the code, and improperly handle issues. In this article, author Jean-Pierre Norguet explains how to design exceptions in order to implement a simple, readable, robust, active, debug-oriented, and user-friendly error-handling system. He proposes the design of a sample exception set, including the source code of a Java implementation. Finally, he explains how to integrate such a design into a Java enterprise application.

The best way to design exceptions in an object-oriented project is never as clear as we would like it to be. Exceptions tend to proliferate in older and larger systems, eventually amounting to hundreds of lines of code. Checked exceptions are required for some common programming scenarios but can create significant processing overhead. And silent catching has been shown to be a source of trouble. Unfortunately, you cannot avoid these mishaps; you must, instead, learn to code your way through them.

In this article I show you that it is possible to satisfy the requirements of an error-handling system with a limited set of exceptions. After establishing the foundation of a good error-handling system, I point out some of the common mistakes in exception design that can undermine application performance. I then present a sample exception set that supports my basic premise: that exceptions intended to help an external system (or user) deal with unexpected conditions should be designed differently from those intended to help the programmer handle expected ones. I explain the semantics of my exception set and also show how the various exceptions would flow through a typical Java enterprise application architecture. Finally, I show you how to implement my exception set in Java.

Requirements of error handling

What is a good error-handling system? Besides aesthetic considerations, a good error-handling system is generally held to meet the following requirements:

  • It is triggered without failure in case of any kind of error in the system.
  • It allows the application to automatically take the appropriate actions.
  • The error message displayed to the user gives a clear description of what is wrong and what action must be taken to proceed.
  • If assistance is required, the error message helps the user to interact with the help desk and gives the help-desk team the necessary information to react easily and quickly.
  • The logged information gives the development team the necessary information to identify the error, locate its source point in the application code, and fix the issue.
  • The error-handling code should not degrade code readability. While essential, error handling is only a safety net, and therefore of less priority than the application's primary functions.

An error-handling system designed to meet these requirements is generally considered to be complete. The question that remains for many Java developers is how to design an error-handling system that makes intelligent use of exceptions, and that is not overloaded by them.

1 2 3 4 Page 1
Page 1 of 4