Master the fundamental concepts of c programming deep dive through this focused micro-challenge.
C has no try/catch, but setjmp/longjmp from <setjmp.h> snapshot the register and stack state, then restore it later. CPython uses this for signal handling; Lua's lua_error unwinds via a similar mechanism; libpng jumps back to a central error handler when a callback fails.
cLoading…
setjmp returns 0 on first entry; after longjmp, it returns the value you passed (never 0, so 0 means "first time")volatileThe exercise wraps this in macros that read like exceptions. Under the hood it is still a switch around setjmp.
For this exercise, you will implement TRY, CATCH, THROW, and FINALLY around file and calculation errors. This task asks you to treat longjmp as exceptional-only control flow, because using it like goto across functions is how production code corrupts stacks.
Keep the relevant man page, ABI doc, or Rust reference chapter open while you work. When your output disagrees with the reference implementation on the same machine, the mismatch is usually an alignment rule, an off-by-one terminator, or a register slot you misread in GDB.
Implement exception handling macros using setjmp/longjmp to simulate try/catch/throw.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github