You can see the following table to understand Java Checked vs Unchecked vs Error.
Factor | checked exceptions | unchecked exceptions | Error |
---|---|---|---|
Compiler check | Checked by the compiler during the compilation time | Not checked by the compiler during the compilation time | Not checked by the compiler during the compilation time |
When raised | Runtime | Runtime | Runtime |
Reason | External resources unavailability | Perform operations on invalid data | Lack 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 exception | We can define custom Error |