It's hard to be perfect, and there are all kinds of anomalies. For example, the program itself has bugs, such as when the program prints the printer does not have paper, such as insufficient memory. In order to solve these anomalies, we need to know the cause of the abnormal occurrence. For some common anomalies, we can also provide a certain response plan. The exception handling in C language is simply achieved by the function return value, but the meaning of the return value is often determined by practice. Programmers need to query a lot of information before they can find a vague reason. Object-oriented languages, such as C + +, Java, and Python, often have more complex exception handling mechanisms. This discusses the exception handling mechanism in Java.
Java Exception Handling
Exception handling
A large part of the Java exception handling mechanism comes from C + +. It allows programmers to skip issues that are temporarily out of the way to continue development, or to make the program smarter to handle exceptions.
Java uses special objects to represent exceptional conditions, such that objects are called exception objects. When an exception occurs, Java throws (throw) The object that represents the current condition, depending on the preset settings. The so-called throw is a special way of return. The thread pauses, stepping out of the method call until the exception handler (Exception Handler) is encountered. The exception handler can catch (catch) The exception object and determine the next action based on the object, such as:
Remind users
Handling Exceptions
Continue Program
Exit program
......
The exception handler looks like this, consisting of try, catch, finally, and subsequent blocks of the program. Finally, it is not necessary.
try {
...;
}
catch () {
...;
}
catch () {
...;
}
finally {
...;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/