Recent articles:
Popular archives:
Java: A platform for platforms
Sun's reorg may seem promising to shareholders but it's also a scramble for position. The question now is whether Sun can,
or wants to, maintain its hold on Java technology. Especially with enterprise leaders like SpringSource and RedHat investing
heavily in Java's future as a platform for platforms
Also see:
Discuss: Tim Bray on 'What Sun Should Do'
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.
What is a good error-handling system? Besides aesthetic considerations, a good error-handling system is generally held to meet the following requirements:
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.
IllegalArgumentExceptions and IllegalStateExceptions.