Skip to content

Control and failure

What runs next

A throw leaves through every frame until a handler; a `finally` runs on the way out and can overrule it. · 10 minutes

Most lines are followed by the next line. Four things break that: `return`, `throw`, `break` and `continue`. Each is a way of leaving, and each leaves through every `finally` it passes on the way out.

A `finally` always runs. That is the guarantee people know. The part they do not is that it is ordinary code, and if it leaves too — with its own `return` or `throw` — its exit replaces the one it interrupted.

function decide() { try { return "first"; } finally { return "second"; } } — what does decide() return?