Java Checked vs Unchecked vs Error

You can see the following table to understand Java Checked vs Unchecked vs Error.

Factorchecked exceptionsunchecked exceptionsError
Compiler checkChecked by the compiler during the compilation timeNot checked by the compiler during the compilation timeNot checked by the compiler during the compilation time
When raisedRuntimeRuntimeRuntime
ReasonExternal resources unavailabilityPerform operations on invalid dataLack of system resources
How to handle Using try-catch block
 We declare exceptions when you feel, the caller method would take decision what need to be done when exception is raised
 Using pre-conditions
 If no option to use pre-conditions then handle with try-catch blocks
 We declare exceptions when you feel, the caller method would take decision what need to be done when exception is raised
We never handle Error as they are irrecoverable
Custom exception We can define custom checked exception We can define custom unchecked exceptionWe can define custom Error
Scroll to Top