Exception and Error both inherit the Throwable class. In Java, only instances of the Throwable type can be thrown or caught. It is the basic type of the exception handling mechanism.
Compare Exception and Error
1. Similarity: Exception and Error both inherit the Throwable class. In java, only instances of the Throwable type can be thrown. , which is a basic component of the exception handling mechanism.
#2. Difference: Exception and Error are the classification of different exception situations by Java designers. Exceptions are expected during normal operation of the program and should be caught and handled accordingly. Error is a situation that is unlikely to occur under normal circumstances. Most Errors will cause the program to be in an abnormal state and cannot be recovered. It is inconvenient and does not need to be captured. Common ones such as OutOfMemoryError are all subclasses of Error.
Exception is divided into checkable (checked) and unchecked (unchecked) exceptions. Checkable exceptions are displayed in the code for capture processing. Uncheckable exceptions are only thrown when the program is running, such as the common NullPointerException.
Recommended learning: Java video tutorial
The above is the detailed content of What is the difference between java exception and Error?. For more information, please follow other related articles on the PHP Chinese website!