Would you believe try-catch-finally works in plain old C?
4 mf_taria 1 5/14/2025, 10:14:50 PM
I was digging through some of my old repositories and found a C language extension I wrote years ago.
Even now, I think it’s kinda cool — and I’d love for you to check it out.
https://github.com/simpart/c-try
It recreates `try {}` / `catch {}` / `finally {}` in plain C using just macros and global variables. There's also a `$` macro to propagate errors between function calls — a bit like a mini DSL for error handling.
You can find a working example in `test.c`.
It doesn't support nesting or multithreading, and yes, it abuses macros. But hey, it's C.
Comments (1)
actionfromafar · 2h ago
Finally!