Using the error class

The error class provides static methods for getting and setting posix and native system errors.

On more-or-less posix-compliant systems, most system calls and C-library functions set the "posix system error" when they fail. Since rudiments uses these functions, when many rudiments methods fail, the posix system error is also set.

Posix defines a bunch of standard error codes like EINTR, ENOMEM, etc. If an error occurs, the posix system error will be set to one of these.

Some platforms, like Windows have their own, "native system error" as well. These platforms usually set both the "native system error" and "posix system error" when a system call or C-library function fails.

Both posix and native system errors can be accessed via the error class.

For platforms that only have posix system errors, the methods for accessing the native sytem error just return the posix system error.

In this example, the posix system error is manipulated directly.

#include <rudiments/error.h>
#include <rudiments/stdio.h>

int main(int argc, const char **argv) {

        error::setErrorNumber(EINTR);

        stdoutput.printf("error number: %d\n",error::getErrorNumber());
        char    *err=error::getErrorString();
        stdoutput.printf("error string: %s\n",err);
        delete[] err;

        error::clearError();

        stdoutput.printf("error number (after clear): %d\n",error::getErrorNumber());
        err=error::getErrorString();
        stdoutput.printf("error string (after clear) : %s\n",err);
        delete[] err;
}