Java Learning Day 19th (exception)

Source: Internet
Author: User

The system of anomalies
Throwable
|--error Serious problems
|--exception
|--runtimeexception run-time exception, we need to fix the code
|--non-RuntimeException compile-time exception, must be handled, or program compilation does not pass

Try...catch...finally
try{

Problem codes that may occur

}catch (Exception name variable) {/////According to the new feature after JDK7 we can add multiple variable exception names (exceptions must be between siblings) when processing

How to Handle

}finally{

Freeing resources

}

Throws
You can't handle it, or you don't have permission to handle it, declare it on the method, tell the caller, there's a problem.

Throw an exception directly behind the class

It is important to note that the exception thrown after the method, if it is a compile-time exception, we call this method must always be resolved, if the runtime of the exception we can not control it.

The difference between throw and throws

Throw
In the method body, followed by the exception object name, and can only be a
Throw throws an exception object, which means there must be an exception here.
Throws
On the method declaration, followed by the class name of the exception, can be multiple
Throws is a method of declaring an exception, which is a possibility, and this exception does not necessarily produce

Finally

Finally is used to free up resources, and its code is always executed. Special case: The JVM exited before executing to finally

Java Learning Day 19th (exception)

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.