Understanding the mechanism of Java exception handling mechanism

Source: Internet
Author: User
Tags throw exception

Look at the abnormal mechanism of the time feel caught the essence of the mechanism, so to say, for beginners should have some help in Java exception mechanism
  1. From the mechanism consists of " Generate exception" "Throw Exception" "catch Exception" "Exception Handling"
  2. The form is divided into four kinds:
    1. The system produces an exception when a bug occurs at run time. The most classic way to throw exceptions
      1. Include "Generate exception""Throw exception "
    2. Throw The form is "first yourself new Exception object, then throw the exception object", anywhere in the code can be manually generated throw
      1. Include "Generate exception""Throw exception "
    3. Try...catch...finally. The most classic way to catch anomalies and handle them
      1. Include catch exception,exception handling
    4. Throws Its function is to forward the exception to the upper layer, it is added to a method, when the method is called, the method may produce an exception, and the exception from the method to send out to the method called this method
      1. Include "catch exception""throw exception "
  3. Can be found to "abnormal handling" of only one, can "produce abnormal" there are two, can "catch the exception" of two, can "throw an exception" but there are three
  4. So the usual forms of application are:
    1. The first use of the "try...catch...finally" or "throws" these two can "catch the exception" of the "exception", "Throw exception" of the "run-time bug system generated anomalies" or "throw"
    2. and then where
      1. The "try...catch...finally" with "Exception handling" or "throw" because it is a "catch exception" with "abnormal processing", so the exception can be handled, and the exception processing ends here.
      2. The "throws", which is a "bug system at run time" or "throw" because it is "catch exception" without "Exception handling", but with "throw exception", so the exception can not be finally processed, the exception will be thrown again. So exception handling to this does not end, it becomes the source of the throw, but also need to be "try...catch...finally" or "throws" again wrapped
        1. So similar to the upper level of the first step, but (the cycle began) with "try...catch...finally" or "throws" two can "catch the exception" of the thing again wrapped "throw exception" of "throws"
        2. And then it was
          1. "Throws" Wrapped in "try...catch...finally", exception can be handled, exception handling to this end
          2. "Throws" wrapped in the "throws", the exception can not be finally processed, the exception will be thrown again, so the exception processing to this did not end, it became the source of the throw, but also need to be "try...catch...finally" or "throws" again wrapped
            1. So the first step back to the upper level, exactly the same, began to circulate

Understanding the mechanism of Java exception handling mechanism

Related Article

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.