error vs exception

Solutions on MaxInterview for error vs exception by the best coders in the world

showing results for - "error vs exception"
Elisa
01 Oct 2016
1Both Error and Exception are derived from Throwable in Java.
2Error represents errors which are generally cannot be handled. For examples:
3OutOfMemoryError, NoClassDefFoundError
4Exception represents errors which can be caught and handled. For examples:
5IOException, NullPointerException
6Exception is divided in two categories; checked and unchecked Exception. 
7Checked Exception require a mandatory try-catch code block to handle it.
8Unchecked Exception mostly represent programming errors (NullPointerException 
9or RuntimeException)
10Errors are unchecked exception and the developer is not required 
11to do anything with these.
12All the Errors are Exceptions, but the reverse is not true.
13In general Errors are which nobody can control or guess when it happened,
14on the other hand Exception can be guessed and can be handled.
15