Appearance
Start with catches that do not need a changed environment
We will add try { … } catch (e) { … } first for try bodies that do not change outer variables. The handler resumes with the environment from entry to the try body. This restriction is part of acceptance, not an assumption that a certificate asks its caller to prove.
The current statement evaluator keeps an environment on normal completion, break and continue. A return or throw keeps only an Except value. It cannot recover a variable's value after a try body assigns that variable and then throws. Passing the entry environment to a handler would give the wrong answer in that case. The translator must therefore refuse outer assignments and calls that change captured state inside a try body.
A caught error must be a modeled thrown value. Some built-in operations currently give no evaluator result where JavaScript throws. Those operations must remain refused inside a try body. No evaluator result must not become an exception that a handler can catch.
The syntax tree will retain both blocks and the catch binding. The parser and printer will preserve the statement through their existing round-trip theorems. The evaluator will distinguish a thrown completion from a returned completion before selecting a handler. Translation must establish that the generated handler makes the same selection under program_sound.
The first version will refuse finally, mutable try bodies and unsupported rethrows from a handler. finally needs rules for overriding an earlier completion. Mutable try bodies need environments on thrown completions and a stronger statement simulation theorem. Rethrows need a typed representation of the caught value that the translator can pass back unchanged. These are separate extensions, not reasons to interpret any of these forms as a no-op.
The implemented first slice uses a syntactic check rather than a call summary. It accepts terminal try statements whose handlers ignore the binding. Protected expressions are primitive literals, names, parentheses, logical negation, typeof of a local name, and strict equality or inequality. Blocks may declare initialized locals, branch, return or throw a built-in Error. Both arms must end with a return or throw.
All calls in the protected body remain refused, including pure calls. The existing call analysis reports whether a function may throw, but not whether all of its runtime errors have modeled values. Property access, arithmetic, other constructors and nested protected try statements remain refused for the same initial analysis boundary. Caught-value tests such as instanceof also remain refused because the source error value does not yet have a local target type shared by all error classes.
The shared checked-guard normalization pass visits both the protected block and the handler. This keeps a checked guard call in an ignored-binding handler aligned with the evaluator and the translator. Inline typeof and null tests continue to narrow through the ordinary branch rules. Calls remain refused in the protected block, so this change does not widen its exception boundary.
This decision settles the initial scope, not the whole of step 17. The remaining forms need the analyses and representations above.
Certificates for built-in Error results retain both completion kinds. They compare callIn with an encoded Except and use program_sound_call, rather than dropping thrown values through runIn. Loops in functions with an Except result still need exception-aware loop invariants. This includes an otherwise pure loop with an early return, because the return slot carries an Except value. The existing loop certificate generator assumes normal state transitions and unwrapped return slots, so those certificates stay refused.
This page is docs/decisions/2026-11-17-try-catch.md at commit 5f1d031.
