Overview
Under normal circumstances, enterprise-level applications correspond to complex business logic, in order to ensure the robustness of the system, it is necessary to face a variety of system business anomalies and run-time anomalies.
Bad exception handling can easily cause application logic to be confusing, fragile and difficult to manage. The application is flooded with fragmented exception handling code that makes the program code obscure, poorly readable, and hard to maintain.
A good exception handling framework provides a unified view of processing for exception handling for applications, separating exception handling from the normal operation logic of the program to provide a more structured and readable program architecture. In addition, a good exception handling framework is extensible, and it is easy to extend the specific exception handling logic according to the specific exception handling requirements.
In addition, the exception handling framework relies on and embodies the system architecture level to some extent. The system architecture determines the subsystems of the system, the interaction between the layers, and the exception handling framework embodies the errors and anomalies of the various interactions in this architecture. Therefore, the exception handling framework is an issue that should be considered in the context of the system architecture.
In this article, we will discuss some aspects of exception-related, and then explore some perspective or design principles for building a robust and extensible exception-handling framework. Since this article introduces some of the concepts of exception-related in the Java language, this article assumes that you are familiar with Java-related basics and understand Java EE and EJB related technologies.
Java Exception Basic Concepts
In the Java programming language, an error-trapping mechanism for exception handling is used. When a program is running, something unusual happens, the program may be interrupted, or the result of the error will occur. In this case, the program does not return any values, but instead throws an object that encapsulates the error message. The Java language provides a special exception handling mechanism to handle these exceptions. As shown in Figure 1, the Java exception architecture:
Figure 1. Java Exception Architecture