Skip to content

finally block is skipped when catch rethrows #93

@RealColdFry

Description

@RealColdFry

Repro:

try {
    try {
        throw 'inner';
    } catch {
        throw 'rethrown';
    } finally {
        print('finally ran');
    }
} catch {
    print('outer caught');
}

Expected: prints finally ran then outer caught
Actual: prints only outer caught

We emit the finally body as plain statements after the ____catch(____error) call:

local ____try = pcall(function() error("inner", 0) end)
if not ____try then ____catch() end   -- ____catch errors ("rethrown")
print("finally ran")                  -- never reached

When ____catch rethrows via error(...), the error propagates past the finally statements, so the finally never runs. Per ECMA-262 sec-try-statement, the Finally block must always run after Catch, including when Catch completes with a throw. Fix: wrap the ____catch call in its own pcall, stash any rethrown error, run the finally, then rethrow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions