One of the most important architectural decisions that Java developers can make is how to use the Java exception model. Java anomalies have long been the target of many controversies in the community. It has been argued that anomaly checking in the Java language has been a failed experiment. This article will discriminate that the reason for failure is not in the Java exception model, but in the Java class Library designers are not fully aware of the method failure of the two basic reasons.
This paper advocates a way of thinking about the nature of abnormal conditions and describes some patterns that are helpful to design. Finally, in the AOP model, we will discuss the processing of exception as the problem of mutual infiltration. When you can use exceptions correctly, they can have great benefits. This article will help you to do this.
Why the anomaly is so important
Exception handling in Java applications reveals to a large extent the strength of the architecture it is based on. Schemas are decisions that are made and followed at all levels of the application. One of the most important is to determine how the class, sub system, or layer of communication in your application is communicated. Java exceptions are ways in which Java methods communicate alternative execution results, so it is worth paying special attention in the application architecture.
A good way to measure the level of Java designers and discipline of development teams is to read the exception handling code in their applications. The first thing to note is how much code is used to catch exceptions, write them into log files, decide what happened, and jump between different exceptions. Clean, straightforward, and highly correlated exception handling often indicates that the development team has a stable way of using Java exceptions. When the number of exception handling code is even greater than other code, you can see that there is a big problem with the communication between the teams (probably not in the beginning), and everyone is dealing with the exception in their own way.
The results of the treatment of sudden anomalies can be predicted. If you ask team members why exceptions are thrown, captured, or overlooked in a particular code, their answer is usually, "I have nothing else to do". If you ask what happens when they write an anomaly that really does happen, they frown and you get an answer like this, "I don't know." We've never tested it before. ”
You can judge from the client's code whether a Java component effectively exploits the Java exception. If they contain a lot of logic to figure out when an operation fails, why it fails, and whether there is room to make up, then the reason is likely to be blamed on the component's error design. The wrong error system produces a lot of "log and Forget" code on the client, which is rarely used. The worst is the twisted logic, the nested try/catch/finally code block, and some other confusion that leads to fragile and unmanageable applications.
To solve the problem of Java anomaly, or not to solve it, is the main cause of the confusion of software project and the lag. Exception handling is a problem that needs to be solved in every part of the design. Establishing an architectural convention for exception handling is the first decision to be made in the project. Using the Java exception model properly has a long-term impact on ensuring that your application is simple, maintainable, and correct.
Parsing exceptions
The proper use of the content contained in the Java exception model has long been controversial. Java is not the first to support exceptions, but it is the first language to execute a rule that declares and handles some exceptions through the compiler. Many people believe that compile-time exception checking is useful for precise software design. Figure 1 shows the level of the Java exception.
Figure 1:java the rank of the exception