[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    Re:  catching errors?
From:       Luiz Henrique de Figueiredo <lhf () tecgraf ! puc-rio ! br>
Date:       1999-08-19 13:39:13
Message-ID: 199908191339.KAA03499 () gauguin ! tecgraf ! puc-rio ! br
[Download RAW message or body]

>From lua-l@tecgraf.puc-rio.br Thu Aug 19 10:22:32 1999
>From: "Brian J. Swetland" <swetland@frotz.net>

>What's the best place to hook into lua's internal error mechanisms?
>
>Does everything go through error() at some point or is there something
>lower down that's better to use?

Everything goes through _ERRORMESSAGE.

To quote the manual:

 4.9 - Error Handling

 Because Lua is an extension language, all Lua actions start from C code
 in the host program calling a function from the Lua library. Whenever
 an error occurs during Lua compilation or execution, function
 _ERRORMESSAGE is called (provided it is different from nil), and then
 the corresponding function from the library (lua_dofile, lua_dostring,
 lua_dobuffer, or lua_callfunction) is terminated, returning an error
 condition.

 The only argument to _ERRORMESSAGE is a string describing the error.
 The default definition for this function calls _ALERT, which prints the
 message to stderr (see Section 6.1). The standard I/O library redefines
 _ERRORMESSAGE, and uses the debug facilities (see Section 7) to print
 some extra information, such as the call stack.

In other words: If you want to change the way the messages are displayed,
redefine _ALERT. For example, you might want to display the message in a
dialog box or write it to a file.
On the other hand, to catch errors, redefine _ERRORMESSAGE.
--lhf

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic