[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Dealing With Errors in Lua
- From: petah <lua@...>
- Date: Sun, 29 Sep 2013 01:30:22 +0200
On Sat, 28 Sep 2013 17:37:55 -0400
Sean Conner <sean@conman.org> wrote:
> I could go through more errors, but basically, they will all fall into one
> of four catagories (in no particular order) [3]:
>
> 1. programming errors, like EBADF (not an open file, or the operation
> couldn't be done given how the file was open originally) or EINVAL
> (invalid parameter) that need to be fixed, but once fixed,
> neverhappens again;
>
> 2. it can be fixed, like EACCESS (bad privileges) or ELOOP (too many
> symbolic links when trying to resolve a filename) but that the fix
> has to happen outside the scope of the program, but once fixed, tends
> not happen again unless someone made a mistake;
>
> 3. better exit the program as quickly and cleanly as possible because
> something bad, like ENOMEM (insuffient kernel memory) just happened
> and things are going bad quickly. Depending upon the circumstances, a
> fast, hard crash might be the best thing to do;
>
> 4. and finally, the small category of errors that a program might be
> able to handle, like ENOENT (file doesn't exist) depending upon the
> context (it could then create the file, or ask the user for a
> different file, etc.).
>
> #1-3 are in the class of "print an error message and stop" (and error()
> will give you something you can print) while #4 is something that could be
> handled (and is handled badly if you use exceptions for this class, in my
> opinion). And in looking over the possible Lua errors [2], I don't think
> there are any in class #4.
Just to avoid any confusion, [2] is just a regex hack to get a very rough idea about the variety of Lua errors outside official error codes. It's in no way comprehensive or scientific, for that matter, i.e. miles away from a serious static code analysis tool with callgraphs and whatnot. (Note to self: do not publish code without a giant disclaimer:)
Specifically, to draw conclusions about your 4th error category (non-terminal errors) you'd have to dig WAY deeper in Lua's C code.
cheers,
-- p
> > [1] http://pubs.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html
> >
> > [2] http://www.laufenberg.ch/lua/dump.log
>
> [3] http://boston.conman.org/2009/12/01.2
>
>