Java exception handling mechanism (exception chain) __java

Source: Internet
Author: User

The JVM (abbreviated for Java virtual machines) uses the method call stack to track a series of method invocation procedures. The stack holds the local information for each calling method. When a new method is invoked, the JVM puts the stack structure that describes the method on top of the stack, and the method at the top of the stack is the method being executed.

If an exception is thrown during the execution of the method, the JVM must find a catch block that can catch the exception
(1) It first observes whether the current method has a catch block and, if it exists, executes the catch code block
(2) If it does not exist, the JVM pops the stack structure of the method from the call stack and continues to find the appropriate catch block in the previous method
(3) when the JVM traces back to the bottom of the call stack, if the code block that handles the exception is still not found, the exception object's Printstacktrace () method is invoked, the exception information from the method call stack is printed, and the entire application is terminated.

Thus, in the process of backtracking, if the JVM finds a block of code in a method that handles the exception, the stack structure of the method is called the top of the stack, and the program process goes on to the exception-handling code portion of the method.

I personally think that in the Java look for anomalies in the first place, through the debugging information table a slowly back to the original exception, need to see the console printstacktrace () printing information, relative to OC, I think OC used exception breakpoint more real, Locate directly in the place where the anomaly occurs. Easy to locate.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.