We can catch exceptions with a try { } catch (ExceptionName e) { }; block. You can add multiple catch blocks to handle different exceptions. The generic catch (Exception e) catches all.
Checked
A checked Exception extends only Exception!
Checked exceptions have to be either handled or announced using the throws keyword as they should be recoverable:
public void throwsStuff() throws CheckedException {
throws CheckedException(); // Allowed
}
public void throwsStuff() {
try {
throwsStuff();
} catch (Exception e) { }; // Allowed
}Unchecked
An unchecked Exception extends RuntimeException and does not need to by caught, nor announced with throws. (But you can catch them)