Card 10/ 10

RecapDifficulty: Advanced1 min

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.

What the topic established, and which card it was on
The ideaWhere
A throw skips every line between the failure and the handlerJava Exceptions: try, catch and finally
Error, checked Exception and RuntimeException are three branches of ThrowableChecked vs Unchecked Exceptions, and Errors
Catch where you can act, declare where the caller has the context, wrap with the causeCatch vs Declare vs Wrap a Checked Exception
A stack trace is captured at the new, top frame firstException Propagation Walkthrough: From throw to catch
finally runs on every way out, and must never returnfinally and return: Why a finally Block Must Not Return
A resource in the try brackets closes itself, before any catchtry-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.