Throw exception in catch block will prevent the finally block executing · Issue #1555 · TypeScriptToLua/TypeScriptToLua · GitHub
Skip to content

Throw exception in catch block will prevent the finally block executing  #1555

Open

Description

@fadabaerobe6
try{
    throw new Exception('test')
}catch(e){
    console.log(e)
    throw e
}finally{
    console.log('end');
}

will compile to

--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
-- Lua Library inline imports
local function __TS__New(target, ...)
    local instance = setmetatable({}, target.prototype)
    instance:____constructor(...)
    return instance
end
-- End of Lua Library inline imports
do
    local function ____catch(e)
        print(e)
        error(e, 0)
    end
    local ____try, ____hasReturned = pcall(function()
        error(
            __TS__New(Exception, "test"),
            0
        )
    end)
    if not ____try then
        ____catch(____hasReturned)
    end
    do
        print("end")
    end
end

In standard JavaScript logic, the content within the finally block should be executed.

Activity

  1. changed the title [-]Throw exception in catch block while prevent the finally block executing [/-] [+]Throw exception in catch block will prevent the finally block executing [/+] on Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions