Way Better Error Handling in C Using CException

Good error handling is necessary for any project of significance (i.e. all of them). But, error handling schemes tend to add all kinds of complexity and ugliness to C code—especially in low-level programming where error cases are most prevalent. Basically, embedded and systems-level error handling code can go one of two ways: a tangled mess of error codes & nested logic or not nearly enough.

This past weekend at GLSEC 2011 I presented a talk on error handling in C and how to improve it considerably with a lightweight exception mechanism. I even got to talk about the smarty-pants semipredicate problem.

The concept of an exception cleans up and simplifies error handling beautifully. Unfortunately, the C language has no native support for exceptions. CException adds a basic exception mechanism to C projects, providing many of the benefits of exceptions as present in higher level languages.

Way Better Error Handling in C Using CException [PDF] (my slides & notes)