RichErrors
A C library for rich (nested) error information
RichErrors: A C library for rich (nested) error information.
Author
Mark A. Tsuchida

RichErrors is a small library for supporting error handling in C or C++ software consisting of multiple dynamically loaded modules (DLLs, shared objects, Mach-O bundles, etc.). It uses a pure C interface for maximum ABI compatibility between modules.

Unlike some C libraries for "exception handling", RichErrors does not use setjmp/longjmp to emulate C++-style exceptions. Instead, it extends the concept of an error code return value and allows construction of nested (wrapped) error objects (cf. Java Exception cause, Python __cause__).

Because integer error codes defined by various subsystems can be valuable information, RichErrors allows explicit wrapping of error codes (together with a specific message string). In order to segregate error codes arising from different subsystems or third-party libraries, every error containing an error code must be assigned a pre-registered "domain".

Known limitations and possible future extensions:

  • The error code domains are global. This limitation could be removed by introducing "realm" objects to which domains and errors belong (with a default global realm).
  • Registration of error code domains is mandatory. We could probably make registration optional, auto-registering any unencountered domain (preserving the current string-interning behavior). Pre-registration could still be optionally enforced.
  • There is no possibility of localized error messages. This is by design because this library was created for use by non-localized software.