The discussions on exception handling seem endless. Many articles and white papers talk about how to handle exceptions. However, what is missing is an extensible, generic exception-handling framework that provides the user with the ability to decide at runtime how to handle exceptions.
The following problems are generally associated with exceptions and their handlers:
Even if we fix the way an exception should be handled, how do we ensure that the developer actually follows the rule? Being a developer myself, I know it's difficult to follow coding rules. I decided to develop a small exception-handling framework, called Patch, that solves the above problems.
The proposed exception-handling framework provides a completely extensible solution. This framework is developed in Java and is freely available for reuse and further development.
Now let's see how the Patch framework solves each exception problem.
This article's exception-handling framework proposes that the client should be able to override the default action performed when an exception occurs, thereby ensuring that, when an exception does occur, the system's behavior suits both the client and the developer. This behavior should be kept outside the main system so that, when the client changes how an exception is handled, the system's main business logic is not affected.
The behavior expected from the exception handler shall hence be defined when the system actually deploys and not during development.
To achieve this behavior, the Patch framework provides a separate set of classes that are used to delegate an exception to the appropriate exception handler. The Patch framework assumes that the following points are always true:
The decision of which exception handler to use is made at runtime using some properties in a configuration file. Taking the above two points into consideration, the Patch framework defines two interfaces:
The PatchBaseExceptionIntf interface must be implemented by all exceptions that need to be handled by the Patch framework:
package com.patch.framework.exceptionhandling.model;
public interface PatchBaseExceptionIntf
{
public void setErrorDetails(ErrorDetails errorDetails);
public ErrorDetails getErrorDetails();
public String toString();
}
Note that this interface uses an object type called ErrorDetails, which I will discuss further in the following section.
| Subject |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
how to deal with ErrorDetails classBy Anonymous on March 30, 2009, 2:14 pmHi Your article is very good one i was looking for such. I would like to know how can we deal with the ErrorDetails class. You did not talk about that a lot in...
Reply | Read entire comment
View all comments