[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: try..catch for Lua 5.2?
- From: Duncan Cross <duncan.cross@...>
- Date: Mon, 13 Sep 2010 19:10:06 +0100
On Mon, Sep 13, 2010 at 6:24 PM, Duncan Cross <duncan.cross@gmail.com> wrote:
> How about a syntax something like this:
Or, another variation - instead of a comma followed by a function
name, an optional assignment expression that can refer to the left
hand side:
try
-- ... [1]
catch e = MyException(e) do
-- ... [2]
catch e = MyOtherException(e) do
-- ... [3]
catch e do
-- ... [4]
end
...which would be sugar for:
try
-- ... [1]
catch _ERROR do
do
local e = MyException(_ERROR)
if e then
-- ... [2]
_ERROR = nil
end
end
if _ERROR then
local e = MyOtherException(_ERROR)
if e then
-- ... [3]
_ERROR = nil
end
end
if _ERROR then
local e = _ERROR
-- ... [4]
end
end
(Except, of course, _ERROR wouldn't really exist as a named variable.)
-Duncan