xroche/coffeecatch
FreeCoffeeCatch, a tiny native POSIX signal catcher (especially useful for JNI code on Android/Dalvik)
About xroche/coffeecatch
CoffeeCatch is a tiny native POSIX signal catcher designed to gracefully recover from signals such as SIGSEGV and SIGBUS by treating them as exceptions. It is particularly useful for JNI code on Android/Dalvik but can also be used in non-Java C projects. The library provides simple macros (COFFEE_TRY, COFFEE_CATCH, COFFEE_END) to protect code sections. In JNI environments, the COFFEE_TRY_JNI macro automatically throws a Java exception upon catching a signal. While it handles most gentle crashes (null pointer dereferencing, integer division, stack overflow), it does not recover from allocator or mutex corruption. The handler is thread-safe, but the client must have exclusive control over signal handlers. For best stack traces, libraries should be compiled with -funwind-tables.
Key Features
Pros & Cons
- Lightweight and easy to integrate into existing projects
- Provides exception-like handling for fatal signals
- Well-suited for Android JNI development where crash recovery is needed
- Open-source and free (MIT-like license implied by GitHub repository)
- Cannot recover from allocator/mutex corruption or complex crashes
- Requires exclusive control over signal handlers (conflicts with other signal handling libraries)
- Best results require compilation with -funwind-tables for stack traces
- Not a comprehensive error recovery solution; only handles 'gentle' crashes