Home  Contents

Error handling

Rawio Core4 Lua Event System

SYNOPSIS

#include <lua/errno.lh>
  1. text, errno = handle:lastError()
  2. handle:clearError()
  3. handle:setError(errno)

DESCRIPTION

When any of the other functions working on a file handle indicates an error condition, the error is stored inside the handle and can be retrieved by calling rawio:lastError().

When the error has been handled by the application, it can be cleared by calling rawio:clearError().

To manually simulate an error condition, pass a numeric errno code to rawio:setError().

RETURN VALUE

If an error has been stored, returns two values: a string describing the error (The result of the C library call strerror() on the errno code) and the errno number from the standard C library.

If no error has been stored, returns nil.

NOTES

Some functions (e.g. rawio:read()) indicate an end-of-file condition by returning an error indicator. Calling rawio:lastError() will return nil, too, in that case, indicating no error.

EXAMPLE

>  >  > 
h = rawio.open("/dev/full") print (h:write("XYZZY")) print (h:lastError())
nil No space left on device 28

SEE ALSO