Repository navigation
Fix try/catch inside a catch clause whose try has a finally - #349
Merged
Merged
Conversation
With a finally, throws in a catch clause stay inside the catch funclet (they invoke into the finally, which ends the catch). A throw inside a try nested in that catch unwinds to the nested try's own pad instead - a top-level pad reached from inside a catchpad, invalid funclet nesting - so even a matching nested catch crashed at run time. Such a throw now ends the outer catch first, as it already did without a finally. An exception the nested catch does not take also skipped the outer finally. A try in its parent's catch clause now chains its mismatch to the parent's finally (new finallyBlockOf / inParentTryCatch side tables), on Windows and on the Itanium path alike. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A try/catch written inside a catch clause crashed when the outer try also had a
finally. It crashed even when the nested catch matched, for example:try { throw 1 } catch (e: int) { try { throw 2 } catch (x: int) {} } finally {}.Without the
finallythis already worked (00nested_catch.ts).Cause (Windows). With a
finally, a throw inside a catch clause deliberately stays inside the catch funclet: it invokes into thefinally, and thefinallyis what ends the catch. A throw inside a nested try is different. It unwinds to the nested try's own pad, which is emitted at the top level (catchswitch within none). So an invoke inside a catchpad unwound to a pad outside it, which is invalid funclet nesting.Fix. A throw inside a nested try now ends the outer catch first, exactly as it already did when there is no
finally.Also fixed. An exception the nested catch doesn't take skipped the outer
finally. A try in its parent's catch clause is not the parent's to catch, but the parent'sfinallymust still run. Its mismatch edge now chains to the parent'sfinally, using the new side tablesfinallyBlockOfandinParentTryCatch. This applies on Windows and on the Itanium (Linux) path.Test. New
00try_in_catch_with_finally.tscovers:finally;finallyblocks running innermost first;Verified locally.
check-x86-eh.sh: 53/53.🤖 Generated with Claude Code