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