00ps 4
00ps 4
---
Checked Exceptions: These are exceptions checked at compile-time. The compiler ensures
these exceptions are either caught in a try-catch block or declared using the throws keyword.
Examples: IOException, SQLException.
Unchecked Exceptions: These are runtime exceptions that are not checked at compile-time.
They typically occur due to programming errors like accessing an invalid index. Examples:
NullPointerException, ArithmeticException.
---
If an exception occurs, the program jumps to the catch block, where the exception is handled.
If no exception occurs, the catch block is skipped, and the program continues executing the
code after the try-catch block.
---
The finally block contains code that is always executed, regardless of whether an exception
occurs.
It is typically used for cleanup operations such as closing files, releasing resources, or resetting
states.
Even if the try block contains a return statement, the finally block will still execute.
---
throws: Used in a method signature to declare that the method might throw certain exceptions.
The caller must handle or propagate these exceptions. Example: void readFile() throws
IOException.
---
Use throw to raise the custom exception when specific conditions are met.
Example:
---