lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Sun, Sep 16, 2018 at 3:14 PM Alysson Cunha <alyssonrpg@gmail.com> wrote:
That "fake" piece of code is so ugly, which makes difficult to others programmers understand your code. 

Besides, it does not handle "finally" correctly because, in case of "finally  execution due error, the error must be raised again



A matter of taste, I think it's less ugly than top-posting on a mailing list, but ymmv.

If you absolutely must have a finally block execute, let me share something I thought was too obvious the first time.

-- try
local success, err = pcall(function()
    -- your chunk goes here
end)
-- catch
if not success then pcall(function()
   -- do stuff with err
     end)
end
-- finally