Wednesday, February 16, 2011

What is the difference between exception and error

An Exception can be caught and recovered:
Any error or problem which one can handle and continue to work normally. Exception can be guessed and can be handled. 
 ArrayIndexOutOfBoundsException means you tried to access a position of an Array that does not exist . 
 
An Error is unrecoverable: OutOfMemoryError means that the JVM has no more memory to continue.

Error: Any departure from the expected behavior of the system or program which stops the working of the system is an error. In general error is which nobody can control or guess when it occurs.

Note that  a compile time error is normally called an "error " while a runtime error is called an "exception."