Plan B User's Manual


Name

error, catcherror, noerror, errmsg ­ Error handling.

Synopsis

#include <ulib.h>

void error(char* e)
int catcherror(void)
void noerror(void)
char* errmsg(void)

Description

Together, these library functions provide a constraint like error handling mechanism. They work like the error handling routines used in Plan 9. The mechanism is important the system raises errors when a system call fails and also when the application wants to handle exceptional conditions or events.

Error is used to raise an error e. This is the equivalent of performing a non-local jump to the place where Catcherror was last called. If there was no such call, the system library catches the error and terminates the process.

Catcherror installs a recovery point for error handling. When called, it returns false. A further call to error would resume execution at the point of the call to catcherror, but this time it would appear to be returning non­zero. After catching an error, further calls to error with a nil argument would re­raise the error, and calls to error with a non-nil argument would both re­raise the error and change the reason for the error.

Noerror is to be called to remove a previously installed recovery point. It is wise to call both catcherror and noerror within the same function that uses the recovery point.

Errmsg returns the error string.

Example

void
doweirdthings(void)
{
if (catcherror()){
die(errmsg());
return;
}
dangerousstuff();
noerror();
}

Source

/src/b/*/u.c

See also

intro(2).


Plan B User's Manual. First edition.