Middle
Name three blocks for exception handling in Java.
sobes.tech AI
Answer from AI
In Java, three main blocks are used for exception handling:
- try — a block where code that might throw exceptions is placed.
- catch — a block that catches and handles exceptions thrown in try.
- finally — a block that always executes after try and catch, regardless of whether an exception occurred or not, usually used for resource cleanup.
Example:
try {
// code that might throw an exception
} catch (ExceptionType e) {
// handle the exception
} finally {
// code that will run in any case
}