Exception classification and handling mechanism

Exception classification:

Exception handling mechanism: throw exceptions, catch exceptions

 Throwing an exception : When an error occurs in a method and an exception is thrown, the method creates an exception object and delivers it to the runtime system. The exception object contains exception information such as the exception type and the program state when the exception occurs. The runtime system is responsible for finding the code that handles the exception and executing it.

Catching exceptions : After a method throws an exception, the runtime system will turn to finding an appropriate exception handler. A potential exception handler is a collection of methods that in turn remain on the call stack when the exception occurs. An exception handler is a suitable exception handler when the type of exception that the exception handler can handle matches the type of exception thrown by the method. The runtime system starts from the method in which the exception occurred, and checks the methods in the call stack in turn, until it finds a method with a suitable exception handler and executes it. When the runtime system traverses the call stack and does not find a suitable exception handler, the runtime system terminates. At the same time, it means the termination of the Java program.

 

Reference link: https://blog.csdn.net/hguisu/article/details/6155636#t1

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325725752&siteId=291194637