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