And look back on the 13th day of Java

Source: Internet
Author: User
Tags finally block try catch

The Java exception handling mechanism mainly relies on the five keyword try catch throw throws finally. A try code block places the code that can take exception, the catch parameter uses the type of exception that indicates the catch, and the exception handling mechanism assigns the thrown exception instance to this parameter, the catch code block code is used to print the exception, the exception is handled, and the catch can have multiple exceptions that are used to catch different types. Finally, you can have a finally to reclaim resources opened in a try code block, regardless of whether there is an exception in the try code block, the Java exception handling mechanism guarantees that the finally block will always be executed. The throws keyword is used in the signature of a method to declare an exception that the method might throw, and the throw keyword is used to throw the actual exception that the Mate statement uses.
We want all errors to be discovered during the compile phase, to try to eliminate all errors before the program runs, but this is unrealistic and the remaining issues must be resolved at run time. Java divides the exception into two kinds, checked exception and runtime exception, Java thinks that checked exception can be handled at compile time exception, so the program handles all the checked exception and runtime exception does not need to handle
Regardless of whether the program code block is in a try block or even a catch block, the system produces an exception object whenever an exception is made to execute the code block. If the program does not define any catch blocks for this code, the Java Runtime Environment must not find a catch block to handle the exception, and the program exits.
Typically, a try block is executed once, and only one catch behind the try block will be executed, and there will never be more than one catch being executed unless the next try block is executed using continue in the loop
The variables in the try block are local variables and cannot be used in catch

And look back on the 13th day of Java

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.