[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: clumsiness of pcall() syntax and how we deal with it
- From: Paul K <paul@...>
- Date: Tue, 28 Apr 2015 19:51:57 +0000
> It's, generally, a cathedral vs. bazaar question. I have seen on this list that pcall() is wrapped to achieve a specific exception handling semantics. But I haven't seen any tweak that would stand out as a novel and interesting way to deal with errors. Mostly everyone is wrapping it to their taste and to achieve a subset of what you can get out of the box in most modern languages.
For the sake of completeness, I just want to mention guard/finalize
proposal that even had a working patch
(http://lua-users.org/lists/lua-l/2008-02/msg00243.html) and a related
proposal on deterministic resource cleanup
(http://john.neggie.net/2009/lua/resource_finalization).
| function appendud(tab, ud)
| tab:beginupdate() finalize tab:endupdate() end
| ud:lock() finalize ud:unlock() end
| for i = 1,#ud do
| tab[#tab+1] = ud[i]
| end
| end
| function user:addfriend(newfriend)
| self.friends:pushback(newfriend) guard self.friends:popback() end
| database:addfriend(self:getname(), newfriend:getname())
| end
I like this syntax and think it's a worthy alternative to try/catch.
Paul.