Difference between Error and Exception?
Difference between Error and Exception?
Let’s learn the difference between Error and Exception.
Error
Errors indicate serious problems or abnormal conditions in the application. The application might not catch or handle the error and may lead to an application crash.
public class Error extends Throwable {
Error and its subclasses are regarded as unchecked exceptions. Unchecked exceptions do not need to be declared in a method/constructor’s throws clause if they are thrown by the execution of the method/constructor and propagate outside the method/constructor boundary.
Exception
Exceptions are unwanted events that interrupt the normal program execution flow.
public class Exception extends Throwable {
Exception and its subclasses are regarded as checked exceptions. Checked exceptions need to be declared in a method/constructor’s throws clause.
Note that the subclasses of the RuntimeException are unchecked exceptions.