Difference Between Error and Exception


Ques:Difference between error and exception 
Ans: Error and Exceptions both areboth inherit fromThrowable..but they are differ by the following ways...
1.Error: Any departure from the expected behavior of the system or program, which stops the working of the system is an error.

Exception:Any error or problem which one can handle and continue to work normally.

2.An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime. While exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.).

3.Error's are irrecoverable exceptions. Usually a program terminates when an error is encountered. but exceptions are recoverable conditions.

4.Errors don't have subclasses while exception has two subclasses, they are compile time exception or checked exception (ClassNotFound Exception, IOException, SQLException etc.) and runtime or unchecked exception(ArrayIndexOutOfBounds Exception, NumberFormat Exception).

People who read this post also read :



0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More