Fix try/catch/finally flow#1729
Merged
Perryvw merged 3 commits intoJun 30, 2026
Merged
Conversation
Contributor
Author
Perryvw
approved these changes
Jun 28, 2026
Perryvw
left a comment
Member
There was a problem hiding this comment.
Looks fine, just needs a npm run fix:prettier
Contributor
Author
|
@Perryvw should be formatted now |
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.
TL;DR
This PR fixes the issue described in #1137.
try/catch/finallyblocks didn't behave correctly when the catch block threw (or re-threw) an error. The finally block would never execute because the error from catch propagated immediately.Example:
function foo(self) do local function ____catch(err) print("Reporting the error ...") error(err, 0) end local ____try, ____hasReturned = pcall(function() compute() end) + local ____rethrow if not ____try then - ____catch(____hasReturned) + ____try, ____rethrow = pcall(function() + ____catch(____hasReturned) + end) end do print("Cleaning up resources...") end + if not ____try then + error(____rethrow, 0) + end end endLogs (-before, +after)
How the fix works
Note: This change only affects
try/catch/finallyblocks.try/catchandtry/finallyare unchanged.We capture any errors from
catchblock into a____rethrowvariable, then let thefinallyexecute, and only then re-throw the error.A few more examples
From unit tests (was broken) ("re-throw (%p)")
From unit tests ("return from catch->finally")
Resources
Closes: #1137