top button

What is difference between error and exception ?

0 votes
posted May 4 by Kavita Patil

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes
Best answer

1) Recovering from Error is not possible. The only solution to errors is to terminate the execution. Whereas you can recover from Exception by using either try-catch blocks or throwing an exception back to the caller.

2) You will not be able to handle the Errors using try-catch blocks. Even if you handle them using try-catch blocks, your application will not recover if they happen. On the other hand, Exceptions can be handled using try-catch blocks and can make program flow normally if they happen.

3) Exceptions in Java are divided into two categories – checked and unchecked. Whereas all Errors belongs to only one category i.e unchecked.

4) The compiler will not have any knowledge about unchecked exceptions which include Errors and subclasses of RunTimeException because they happen at run time. Whereas compiler will have knowledge about checked Exceptions. The compiler will force you to keep try-catch blocks if it sees any statements which may throw checked exceptions.

5) Exceptions are related to application whereas Errors are related to the environment in which application is running.

answer May 6 by Arunkumaarts