lua-users home
lua-l archive

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


On 9 July 2015 at 02:10, Simon Green <Simon.Green@2degreesmobile.co.nz> wrote:
Hi all,

I’m relatively new to Lua
 [...]
Noting that there are no exceptions in Lua.
 [...]
Cheers
Simon

If you're 1) new to Lua, from some C++/C# like language, 2) not mega-concerned about speed and memory allocations, and 3) Not ready to think about metatables, tail calls and other advanced features mentioned in previous answers, then IMO a variation of Soni L's first answer is the most readable for noobs:

local thing = nil
pcall (function() thing = a.b.c.d.e end) -- swallows the error, thing remains nil
if thing == something then
  something-else
end

You say "Noting that there are no exceptions in Lua".  There are errors, which are very much like exceptions.  They can be caught with pcall.

Peter