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.