Skip to content

Cannot re-throw in catch clause #245

@tomblind

Description

@tomblind

Example:

function broken()
{
    throw "foobar";
}
try
{
    broken();
}
catch(e)
{
    throw `${e}`;
}
print("everything is fine");
function broken()
    error("foobar")
end
xpcall(function()
    broken();
end,
function(e)
    error(""..tostring(e).."")
end)
print("everything is fine");

The problem with this is the error will be silently eaten and the code after will be executed (whereas, in JS, execution would stop at the re-throw).

Something like this might be a better way to go than using xpcall:

function broken()
    error("foobar")
end
local __TS_try, e = pcall(function()
    broken();
end)
if not __TS_try then
    error(""..tostring(e).."")
end
print("everything is fine");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions