What is the difference between error and exception in Java?

Source: Internet
Author: User
Tags throwable

Error classes are good exception classes inherit from Throwable classes.

Inheritance relationship of the error class:

Java.lang.Object

--java.lang.throwable

--java.lang.error

Exception Inheritance Relationship:

Java.lang.Object

--java.lang.throwable

--java.lang.exception

The difference between the two:

Exception:

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

2. Indicates an error caused by improper coding by the programmer

3. Should be handled at the procedural level

Error:

1. Always uncontrollable (unchecked)

2. Often used to indicate system errors or low-level voluntary errors

3. Should be handled by the system level

Two types of exceptions are defined in Java:

1. Checked exception: This kind of exception is exception subclass. Exceptions are handled by the upward throw mechanism, and if a subclass can produce a exception, then a throws must also be in the parent class. Possible problems: Low code efficiency and high coupling.

2.Unchecked exception: Such exceptions are runtimeexception subclasses, although runtimeexception are also exception subclasses, but they are extraordinary and cannot be passed through the client Code to try to solve, so called unchecked exception.

Other than that:
Error indicates that recovery is not an impossible but difficult situation with a serious problem. For example, memory overflow. It is impossible to expect the procedure to handle such a situation.

Exception represents a design or implementation problem. That is, it means that if the program is working correctly, it will never happen.

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.