Interview Question

What is an exception?

Exceptions are Throwable objects used for abnormal control transfer.

💡 Concept ✅ Quick Revision ☕ Java

Answer

An exception is an object whose abrupt throwing transfers control to a matching handler. • Throwable is the root of Error and Exception. • A catch clause handles assignment-compatible thrown types. • finally and try-with-resources support cleanup.

Example

Code
try {
    throw new IllegalArgumentException("bad value");
} catch (IllegalArgumentException exception) {
    System.out.println(exception.getMessage());
}
Output
bad value

Quick Revision

Exceptions are Throwable objects used for abnormal control transfer.