Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the differences between Error and Exception in Java

Shulou Source: shulou.com Published: 2022-06-02 08:19:21 10月30日 Update

This article mainly introduces what is the difference between Error and Exception in Java, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.

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

Inheritance relationship of Error:

Inheritance relationship of Exception:

The differences between the two:

Exception:

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

2. Represents an error caused by a programmer.

3. Should be processed at the application level.

Error:

1. It is always unchecked.

2. Errors often used to represent system errors or low-level resources.

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

Two types of exceptions are defined in Java:

1) Checked exception: these exceptions are subclasses of Exception. The up-throw mechanism of the exception is handled, and if the subclass may produce an An exception, then the throws An exception must also be 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 they cannot be solved by client code, so they are called Unchecked exception.

Inheritance diagram of exception classes in Java:

Thank you for reading this article carefully. I hope the article "what is the difference between Error and Exception in Java" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Subclasses articles errors controls programs systems processes differences code values interests at the same time applications efficiency more friends mechanisms knowledge programmers editing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information NVidia Apple MariaDB