A lightweight, portable exception handling library for C using setjmp/longjmp, designed for embedded systems and performance-critical applications.
CException is a lightweight exception handling library for the C programming language. It provides Try/Catch/Throw semantics using the standard C setjmp/longjmp mechanism, allowing developers to handle errors cleanly without the overhead of C++ exceptions. It solves the problem of ugly error code propagation through long chains of function calls in C applications.
C developers working on embedded systems, real-time applications, or any performance-critical projects where clean error handling is needed without the bloat of full exception frameworks.
Developers choose CException because it's significantly faster than C++ exceptions, portable to any platform with setjmp/longjmp, and simple to integrate—offering basic exception handling without complex features that would impact performance in constrained environments.
Lightweight exception implementation for C
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses standard setjmp/longjmp for exception handling, making it significantly faster than C++ exceptions and ideal for performance-sensitive environments like embedded systems.
Works on any system with setjmp/longjmp, including embedded and real-time operating systems, ensuring portability without complex dependencies.
Provides Try, Catch, and Throw macros that mimic exception patterns from higher-level languages, reducing boilerplate compared to error code propagation.
Configurable with unique task IDs for single or multi-tasking systems, making it suitable for RTOS environments where multiple stacks are present.
Requires local variables to be marked volatile if accessed after a Throw, adding complexity and potential for bugs due to compiler optimizations.
Does not automatically free malloc'd memory or release resources on exceptions, forcing manual cleanup in Catch blocks and increasing development overhead.
Prohibits returns and gotos within Try blocks, which can limit coding patterns and lead to memory leaks if developers inadvertently bypass cleanup steps.