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 and an error code.

If the error code is a positive number, it is an errno code from the standard C library. The descriptive string that is returned is the result of calling the C standard function strerror() with that code.

If the error code is a negative number, it is an error reported by the PolarSSL library. The descriptive string in that case is also retrieved from PolarSSL.

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

rawio.strerror