|
On Sat, Sep 15, 2018 at 3:00 PM Peter Hickman <peterhickman386@googlemail.com> wrote:On Sat, 15 Sep 2018 at 11:58, Alysson Cunha <alyssonrpg@gmail.com> wrote:try-catch and try-finally language sugars for pcall to simplify error handlingThis is the one thing that would make things much easier for me. I know we should wrap things in pcall incase they fail but there are so many things that *could* fail the resulting code becomes unreadable very quicklyA few judicious try-catch blocks can provide much robustness without obscuring the code. I tend to write code in a more iterative fashion with a few large scoped try-catch blocks (or begin-rescue-end as I'm actually a Ruby programmer) until the part of the code that is fragile comes to lightThis can be adequately faked:-- trylocal success, err = pcall(function()-- your chunk goes hereend)-- catchif not success then-- do stuff with errend-- finallyI understand that this may be more a case of "trying to write Ruby in Lua" but I miss this more I miss OOP. I have no problem with Lua not being an OOP language, it's easy to adapt to. But catching errors seems to require chopping up the code in unnatural ways so that it can be stuffed into a function that can be pcalledOtherwise it's still a wonderful language