What is the difference between error and exception?

Exceptions are those which can be handled at the run time whereas errors cannot be handled.

An exception is an Object of a type deriving from the System.Exception class. SystemException is thrown by the CLR (Common Language Runtime) when errors occur that are nonfatal and recoverable by user programs. It is meant to give you an opportunity to do something with throw statement to transfer control to a catch clause in a try block.
 
An error that occurs during runtime is not recoverable whereas in most of the cases an exception can be recovered if it occurs during run time.

Key difference: Both, error and exceptions are derived java.lang.Throwable problems. An ‘error’ is a serious problem that cannot be recovered once occurred, whereas an ‘exception’ is a problem which can be handled and corrected after execution.

An ‘error’ in Java is a serious problem, which once occurred cannot be handled and recovered. An error is defined as “any departure from the expected behavior of the system or program, which stops the working of the system”. It comes under the Throwable class, which categorizes it as a serious and reasonable application. After its execution, this application re-occurs several times, creating an interruption in the systems functions. There are several subclasses under the error form. These errors occur at specific levels and functions, and are handled by specific functions. In a broader way, these errors can be broken into two categories: Design-time errors and Logical errors.

Basically, there are two main types of errors and their conditions:

Run-time error: These are executed at the running of the program.
Compile-tile error: These are executed at the compiler, during the compiling time.

Further these types are subdivided into other forms.
 
Back
Top