[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Exceptions (was Re: Custom extensions to Lua)
- From: Mark Hamburg <mhamburg@...>
- Date: Thu, 11 Aug 2005 09:28:13 -0700
on 8/10/05 4:57 PM, Rici Lake at lua@ricilake.net wrote:
> There
> is
> really no excuse for not using a standard Lua mechanism for returning
> errors.
I think part of the issue is that Lua has a couple of methods for reporting
errors:
1. Throw an error with the error function (or its compatriot assert). Note
that you have to do a little extra work if you don't want it annotated with
information about where it was thrown from. That information is useful for
debugging, but not as useful when you want to process the error on the
catching end.
2. Return nil plus an error message. This can be translated into the first
form via assert though again we run into the annotation issue.
Diego has built an approach in Lua socket that combines the two, but it
requires a certain amount of discipline to use since it depends on using
exceptions for error handling within modules and nil + message at module
boundaries.
Furthermore, there are standard APIs that use both mechanisms. For example,
if you pass something other than a string to io.open, you get an exception
rather than nil plus a message.
So, this thread could be seen as a call for sorting out a set of rules that
are easy to follow and then trying to bring as much code as possible in
compliance with them.
Mark