libcexceptions
README.md
libcexceptions
Summary
Tiny C library, which allows you to catching exceptions.
IMPORTANT: Returning a value (exiting a function) inside the context of catching an exception will cause your program to work incorrectly
Installation
or$ make cexceptions
- builds distr$ make all
$ tree distrbuild├── include│ └── cexceptions.h└── lib └── libcexceptions.so
- make install - builds distr and copies it's content (
) tobuild/*
(by defaultprefix_path
)/usr
Usage example:
#include <stdio.h>#include <cexceptions/cexceptions.h>
void nested_function(){ throw(THROWABLE_INVALID_ARGUMENT, "test", -1, NULL); //Throws an Exception with type=2}
int main(int argc, char ** args){ try(){ // Pushes new TryCatchContext CONTEXT1 into defaultTryCatchContextStack try(){ // Pushes new TryCatchContext CONTEXT2 into defaultTryCatchContextStack nested_function(); }catch(THROWABLE_RUNTIME_ERROR){ // Cathces exception with type=EXCEPTION thrown in CONTEXT2 of defaultTryCatchContextStack }catch(){ // Catches Exceptions with any type differs catched before propagate(); // Propagates unhandled Exception to CONTEXT1 of defaultTryCatchContextStack }etry() // Finalizes CONTEXT2 }catch(){ // Catches Exceptions with any type thrown in CONTEXT1 (or propagated from nested contexts) fprintf(stderr, "%T\n", thrown()); // Printing catched Exception }etry() // Finalizes CONTEXT1}