Errors vs Exceptions
|
ERROR |
EXCEPTION | |
|---|---|---|
|
Basic |
caused due to a lack of system resources |
caused because of the code |
|
Recovery |
irrecoverable |
recoverable |
|
Keywords |
no means to handle an error by the program code |
handled using three keywords “ |
|
Consequences |
will terminate program abnormally |
is thrown and caught by the “ |
|
Types |
unchecked exception |
checked exception or unchecked exception |
|
Package |
“ |
“ |
|
Examples |
|
|
Checked Exceptions vs Unchecked Exceptions
|
CHECKED EXCEPTION |
UNCHECKED EXCEPTION | |
|---|---|---|
|
Basic |
|
|
|
Class of Exception |
|
|
|
Handling |
|
|
|
Compilation |
|
|
Diagram
/java-platform/java/java---projects--and--code-examples/java---native-libraries/java---lang/java---throwable---errors-vs-exceptions---unchecked-vs-checked/checked-and-unchecked-exceptions-in-java.png)
/java-platform/java/java---projects--and--code-examples/java---native-libraries/java---lang/java---throwable---errors-vs-exceptions---unchecked-vs-checked/checked-and-unchecked-exception-error.jpg)
Throwableis the parent class of the classesErrorandException- unchecked exceptions - are the subclasses of
RuntimeExceptionand the subclasses ofError - checked exceptions - are the remaining subclasses of
ExceptionexceptRuntimeException