Exception in Java

Checked Exception vs Unchecked Exception
| Β | Checked Exception | Unchecked Exception |
|---|---|---|
| When checked | checked at compile time. | not checked at compile time, it occurs at runtime. |
| Handling exception | A checked must be handled either by re-throwing or with a try-catch block | whereas an unchecked isnβt required to be handled. |

Checked Exception
- These are the exceptions that are checked at compile time.
- If some code within a method throws a checked exception, then the method must either handle the exception or it must specify the exception using the throws keyword.
A fully checked exception
- A fully checked exception is a checked exception where all its child classes are also checked, like IOException, InterruptedException.
A partially checked exception
- A partially checked exception is a checked exception where some of its child classes are unchecked, like Exception.
Unchecked Exception
- These are the exceptions that are not checked at compile time.
- It is not forced by the compiler to either handle or specify the exception. It is up to the programmers to be civilized, and specify or catch the exceptions.
[Reference]
Comments powered by Disqus.