Card 10/ 10
Recap: Exceptions
Throwing, the three branches, three responses, propagation, finally and resources, with where each was.
Exceptions come down to the six ideas below, each listed with the card that covers it.
| The idea | Where |
|---|---|
| A throw skips every line between the failure and the handler | Java Exceptions: try, catch and finally |
Error, checked Exception and RuntimeException are three branches of Throwable | Checked vs Unchecked Exceptions, and Errors |
| Catch where you can act, declare where the caller has the context, wrap with the cause | Catch vs Declare vs Wrap a Checked Exception |
A stack trace is captured at the new, top frame first | Exception Propagation Walkthrough: From throw to catch |
finally runs on every way out, and must never return | finally and return: Why a finally Block Must Not Return |
A resource in the try brackets closes itself, before any catch | try-with-resources: Closing Files Automatically |
Every decision in this topic is about who should deal with the failure. Catching narrowly, declaring upwards and wrapping with a cause are three answers to that question, and an empty catch is a refusal to answer it.
← → move through sections and cards