#include "../src/ExceptionalScope/ExceptionalScope.h" #include #define unsafe void print(const char* s) { unsafe { puts(s); } } int main() { ExceptionalScope scope; ExceptionalScope_Create(&scope); scope.exception = (void*) 0xCAFEBABE; try(&scope) { ExceptionalScopeCleaner outerCleaner = { .next = NULL, .arg = "Unwinding the cleaner stack #2", .action = (ExceptionalScopeCleanerFunction) print, }; withScopedCleaner(&scope, outerCleaner) { ExceptionalScopeCleaner innerCleaner = { .next = NULL, .arg = "Unwinding the cleaner stack #1", .action = (ExceptionalScopeCleanerFunction) print, }; withScopedCleaner(&scope, innerCleaner) { ExceptionalScope_Throw(&scope, (void*) 0xDEADBEEF); puts("After the throw"); } } } catch { printf("Caught an exception: %p\n", scope.exception); } ExceptionalScope_Destroy(&scope); }