[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Try-catch and try-finally
- From: "Soni L." <fakedme@...>
- Date: Tue, 31 May 2016 13:29:21 -0300
On 31/05/16 08:17 AM, Jonne Ransijn wrote:
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
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.
You'll hate Python, then.
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.