Java exception Mechanism

Source: Internet
Author: User
Tags try catch

Java exception Mechanism

Java exception Mechanism

I have nothing to do after work. Let's take a look at the basic java knowledge and make a summary.

Exception mechanism: a control process solution provided by java to solve emergencies or misoperations


Throwable all errors or exceptional superclasses, including two subclasses: Error and Exection


The Error is not handled by the program, such as memory overflow or machine power failure.

Exception exceptions include runtime exceptions and compilation exceptions.

Runtime exception classes all inherit RuntimeException, common such as NullPointerException, ArithmeticException, IndexOutOfBoundsException, etc.

Compilation exception, non-runtime exception, must be processed during compilation, such as IOException (subclass such as FileNotFoundException)


Exception Handling:

1) try {

// Action to be executed by the program

} Catch (Arthur meticexception e ){

// Actions that the program may execute

E. printStackTrace ();

} Catch (Exception e ){

// Actions that the program may execute

} Finally {

// The action that the program will execute

}

Tip: You can use return to learn more about try catch.

Note: When multi-layer catch occurs, the exception class range is large.

2) throws and throw

Throws declares an exception.

Throw throws an exception object.

Note: An exception is thrown when an exception is declared. If the caller does not handle the exception, the caller will continue to throw the exception.


Custom exception:

You can customize your own Exception classes as needed, and normally define the Exception classes that inherit exceptions.


To be continued ....









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.