What is the difference between error and exception?

Both Error and Exception are derived from java.lang.Throwable in Java but main difference between Error and Exception is kind of error they represent. java.lang.Error represent errors which are generally can not be handled and usually refer catastrophic failure e.g. running out of System resources, some examples of Error in Java are java.lang.OutOfMemoryError or Java.lang.NoClassDefFoundError and java.lang.UnSupportedClassVersionError. On the other hand java.lang.Exception represent errors which can be catch and dealt e.g. IOException which comes while performing I/O operations i.e. reading files and directories. Clear understanding of Error and Exception is must for any serious Java programmer and good programming and debugging skills are required to overcome issues which caused Error and Exception in Java.

Bulkmailstack
 
An Error is something that most of the time you cannot handle it. Errors are unchecked exception and the developer is not required to do anything with these. Errors normally tend to signal the end of your program, it typically cannot be recovered from and should cause you exit from current program. It should not be caught or handled.

All the Errors are Exceptions but the reverse is not true. In general Errors are which nobody can control or guess when it happened, on the other hand Exception can be guessed and can be handled.

Rentalproxies
 
Back
Top