lua-users home
lua-l archive

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

I do not think this will ever be added to Lua.

Exceptions should be used as exactly that: Edge cases wherein the requested action cannot be completed.

Some people in the Java and C# community seem to disagree, but in case of an exception the program should crash. There is NO valid reason to ever catch a PathTooLongException or AssertException, except at the very top of the program, to print an error message.

Furthermore, THROWING an exception is usually bad design. If you do throw, make sure your case is ACTUALLY an exception, not just something that you don't care about (e.g. sin 360.0° = 0, NOT an exception)

The only reason why you should ever need to catch exceptions is to print error messages, or to protect your program from crashing when doing something dangerous (e.g. calling a external library), especially in Lua, where errors are generally strings not objects.

That said, pcall is powerful enough for what most people need (i.e. printing error messages), and for those who need more, for whatever reason that may be, there are several ways to achieve identical results as try-catch-finally statements.