henesyinit from lsubb0c8bdb6 years agoHistory
90 lines · 1.5 KB · Text
RawDownload
.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