[Xcb] problem with the use of the shm extension

Vincent Torri Vincent.Torri at iecn.u-nancy.fr
Mon Oct 17 22:10:32 PDT 2005


>
> Therefore the user doesn't have to check the status after each and every
> cairo_*() function call, they're free to write "cleaner" code and only
> check the status at various way-points.
>
> So instead of code that looks like this:
>
> 	if (cairo_moveto (cr, x, y) != CAIRO_STATUS_SUCCESS) {
> 		error ();
> 	}
> 	if (cairo_lineto (cr, x, y) != CAIRO_STATUS_SUCCESS) {
> 		error ();
> 	}
> 	if (cairo_set_source_rgb (cr, r, g, b) != CAIRO_STATUS_SUCCESS) {
> 		error ();
> 	}
> 	if (cairo_fill (cr) != CAIRO_STATUS_SUCCESS) {
> 		error ();
> 	}
>
> A user can write code that looks like:
>
> 	cairo_moveto (cr, x, y);
> 	cairo_lineto (cr, x1, y1);
> 	cairo_set_source_rgb (cr, r, g, b);
> 	cairo_fill (cr);
> 	if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) {
> 		error ();
> 	}
>
> Which is considered easier to read.
>
> As another example, the png library has its users call the setjmp(3)
> function to define a location to jump to should an error be
> encountered. In this way an application can setup various cleanup
> routines at the jumped-back-to location. libpng will jump to this
> location when it encounters an error unless you pass in three function
> pointers to an init routine: two are function pointers to handle
> warnings and errors, and the third is a pointer to user-data which gets
> passed to the functions should they be called.

This is how exceptions in C can be implemented. It uses setjmp and
longjmp. There are examples here :

http://www.math.umd.edu/~asnowden/c-except.html
or
http://ldeniau.home.cern.ch/ldeniau/html/exception/exception.html

The exceptions in these examples is not as powerful as exceptions in C++,
but maybe you'll find them interesting.

I think that google can give you more examples about exceptions in C.

Vincent


More information about the Xcb mailing list