Turn: The difference between error and exception in Java

Source: Internet
Author: User

Both the error class and the exception class inherit from the Throwable class.

The inheritance relationship of error:

Exception's inheritance relationship:

The difference between the two:

Exception:

1. Can be controllable (checked) or uncontrolled (unchecked).

2. Represents an error caused by a programmer.

3. Should be handled at the application level.

Error:

1. Always uncontrollable (unchecked).

2. Often used to represent errors in system errors or low-level resources.

3. If possible, it should be captured at the system level.

Two types of exceptions are defined in Java:

1) Checked exception: This type of exception is a subclass of exception. The exception is handled by an up-throw mechanism, and if the subclass can produce a exception, then the throws a exception must be in the parent class. Possible problems: Low code efficiency, high coupling.

2) Unchecked exception: This kind of anomaly is runtimeexception subclass, although RuntimeException is also a subclass of exception, but they are extraordinary, they cannot pass the client Code to try to solve, so called unchecked exception.

Inheritance diagram for exception classes in Java:

Turn: The difference between error and exception 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.