Java exception mechanism

Source: Internet
Author: User
Java exception mechanism

The java.lang.Throwable types in Java inherit from the. Error type inherits from Java.lang.Error. The Exception type inherits from Java.lang.Exception.

For example:

1.IllegalAccessException exception

2.IllegalArgumentException exception

3.IllegalAccessError

Abnormal and non-checked anomalies

Both RuntimeException and error are compiled without capture, known as non-checked exceptions. (Of course both can be captured)

All other exception types need to be captured.

If a method throws a checked exception and does not capture itself, the throws must be declared at the tail of the function signature for capture.

Note: If a catch statement attempts to catch a checked exception, the checked exception or its subclass must be thrown in the try statement, or the compilation will be an error.

For example

Try {    System.out.println ("Nothing Happened");
}
catch(illegalaccessexception e) { System.out.println (e); }
The meeting error "Cannot throw exception error in the body of the corresponding try statement illegalaccessexception"

Method can throw an exception at any location using throw.

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.