Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the differences between Error and Exception in Java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report