Java exception mechanism

Source: Internet
Author: User
Tags try catch

On Java anomaly mechanism

Work idle come to nothing, look at the basics of Java, do a summary

Exception mechanism: A solution to a control process that is provided by Java to resolve an unexpected or misoperation operation


Throwable all errors or exceptions, containing two subclasses of error and Exection


Where error errors are not handled by the program, such as memory overflow, machine power off, etc.

Exception exceptions include run-time exceptions and compile-time exceptions

Run-time exception classes are inherited runtimeexception, common such as nullpointerexception,arithmeticexception,indexoutofboundsexception, etc.

Compile-time exceptions, non-runtime exceptions, must be processed when compiling, such as IOException (subclasses such as FileNotFoundException)


Exception handling:

1) try{

Action to be performed by the program

}catch (Arthmeticexception e) {

Actions that the program may perform

E.printstacktrace ();

}catch (Exception e) {

Actions that the program may perform

}finally{

The action that the program is bound to perform

}

Tip: You can learn more about the process of Try catch by return

Note: Exception class scope size problem in multi-layer catch

2) throws and throw

Throws is declaring an exception

Throw throws a real exception to the object

Note: An exception is thrown where the exception is declared, and if the caller does not process it, the exception will continue to be thrown up


Custom Exceptions:

You can customize your own exception class as needed, and define the exception class that inherits exception normally.


Cond....









Java exception mechanism

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.