What is the difference between error and exception?

Source: Internet
Author: User
Tags throwable

Both the error and exception classes inherit from the throwable class.

Inheritance relationship of error:

Java. Lang. Object
-- Java. Lang. throwable
-- Java. Lang. Error

The inheritance relationship of exception:

Java. Lang. Object
-- Java. Lang. throwable
-- Java. Lang. Exception

Differences between the two:

Exception:

1. It can be controllable (checked) or unchecked)

2. indicate an error caused by a programmer

3. It should be processed at the application level

Error:

1. Always unchecked)

2. It is often used to indicate system errors or low-level resource errors.

3. How can this problem be captured at the system level?

Java defines two types of exceptions:

1) Checked exception: these exceptions are subclasses of exception. Exception is thrown up. If the subclass may produce a exception, throws a must also be thrown in the parent class. Possible problems: Low code efficiency and high coupling.

2) unchecked exception: these exceptions are all subclasses of runtimeexception. Although runtimeexception is also a subclass of exception, they are extraordinary and cannot be solved through client code. Therefore, they are called unchecked exception.

In addition:

Error indicates that recovery is not a serious problem that is impossible but difficult. For example, memory overflow. It is impossible to expect the program to handle such a situation.

Exception indicates a design or implementation problem. That is to say, it indicates that if the program runs normally, 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.