ERROR(2) ERROR(2) NAME estrdup, emalloc, erealloc, errinit, noerror, error, warn, catcherror, dprint - local error handling utilities SYNOPSIS #include <u.h> #include <libc.h> #include <error.h> char* estrdup(char*) void* emalloc(int); void* erealloc(void*,int) void dbgprint(char* fmt, ...) void errinit(Error* e) void noerror(void) void error(char* msg, ...) void warn(char* msg, ...) void catcherror(void) DESCRIPTION These routiles are tools for error handling. The ones named like standard functions with the letter e prepended behave as expected. However, they check that the standard routine did its work and call sysfatal(2) otherwise. catcherror, noerror, error, and errinit provide exeption handling for C, in the same style of the similar routines used in the kernel. The only difference is that errinit should be called before using any other. They can be used both with and without the thread(2) library. Dprint is like fprint(2) but prints only if the global debug is true. Beware that it is a macro and has a conditional statement. Always suround it with braces when used within if statements. SOURCE /sys/src/liberror EXAMPLE Catch an error, and raise one. void f(void) { error("raise this!"); } void main(int argc, char **argv) { Page 1 Plan 9 (printed 12/22/24) ERROR(2) ERROR(2) Error e; errinit(&e); if (catcherror()){ sysfatal("catched: %r"); } f(); noerror(); } Page 2 Plan 9 (printed 12/22/24)