[!INDEX]
- Definition
- Compile-Time Exception (Checked Exception)
- Runtime Exception (Unchecked Exception)
- points to remember
1. Definition
[!NOTE]
- The key difference between compile-time exceptions and runtime exceptions in Java revolves around when they are caught or handled, as well as their causes. Here's a detailed comparison to help clarify the distinction:
2. Compile-Time Exception (Checked Exception)
[!NOTE]
- Exceptions that are checked by the compiler during the compilation of the program.
- Exception must be caught using a try-catch or with the throws keyword.
- Forced to handle these exceptions.
- Recoverable conditions.
3. Runtime Exception (Unchecked Exception)
[!NOTE]
- exceptions that occur during the execution of the program, not checked at compile time.
- does not force the programmer to handle or declare runtime exceptions.
- Occur during the program’s execution.
- they don't need to be declared or handled explicitly by the programmer.
4. points to remember
[!important]
- Both checked (compile-time) and unchecked (runtime) exceptions occur at runtime—they don't actually "happen" during compilation. However, the main difference is how they are handled or checked by the Java compiler before the program runs.