Note: this is a breaking change!
I would like to see the semantics of try/catch be changed to make it (in my opinion) more useful.
I think that
x = try
do_something()
catch err
handle_error(err)
should be changed from compiling to
local x = xpcall(function()
return do_something()
end, function(err)
return handle_error(err)
end)
into compiling to this:
local x = select(2, xpcall(function()
return do_something()
end, function(err)
return handle_error(err)
end))
The addition of select(2, [...]) causes the boolean that's normally returned by xpcall() to be skipped. This would feel more natural to use in many cases, and allow for patterns like this:
x = (try maybe_failing_operation()) ?? "default"
Note: this is a breaking change!
I would like to see the semantics of
try/catchbe changed to make it (in my opinion) more useful.I think that
should be changed from compiling to
into compiling to this:
The addition of
select(2, [...])causes the boolean that's normally returned byxpcall()to be skipped. This would feel more natural to use in many cases, and allow for patterns like this: