Exceptions in Java

Source: Internet
Author: User
Execution order of Try-catch blocks

Put the code that might appear to be the exception in the try block, and if an exception occurs, execute the statement in the catch block without executing the statement that follows the try block, to catch and handle the exception.

If you have multiple catch blocks, you need to be aware of the order of the catch blocks, which must be "from subclass to parent class." If one of the catch and exception types is the same, the rest of the catch block is not executed.

Execution order of try-catch-finally blocks

The contents of the finally block are "always executed". Regardless of whether an exception occurred.

If a return statement is in both the try block and finally block, the return statement in finally is always executed.

Declaring and Throwing exceptions

Declare exceptions using the throws keyword followed by the exception type. Throws must be followed by the method parameter list, cannot be used alone, and can declare multiple exceptions.

Throws an exception using the Throw keyword.

Exception chain

The exception chain in Java is that when Try-catch handles an exception, it does not process in the catch, just throws the exception information and the exception object again, and captures and processes the previous layer.

   

Exceptions in 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.