Exceptions in Java

Source: Internet
Author: User

1. Catching exceptions

try{
Code Block 1
}catch (Exception e) {
Code Block 2
}finally{

}
Catch is the exception in fetch code block 1
Code Block 2 is handled after an exception

Code block 3 is executed regardless of the exception, if there is a return in Generation 1 or Generation 2, Generation 3 will be executed after return

2. Customizing exceptions and Throwing exceptions

1.1 Throw is a statement that throws an exception.
Syntax: Throw (Exception object);
Throw e;

1.2 throws is a declaration in which the method may throw an exception. (used when declaring a method, indicating that the method might throw an exception)
Syntax: [(modifier)] (return value type) (method name) ([parameter list]) [Throws (Exception Class)]{...}
public void DoA (int a) throws exception1,exception3{...}

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.