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");
Example:
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: