An error-handling library for C program.
Cachalot is more like a protocol rather than a library.
Here is the philosophy behind cachalot:
- simple: only 8 APIs.
- safe: if something wrong happens inside cachalot, the caller program will not be affected.
Here is the protocol behind cachalot:
- If an error happens somewhere in the caller program, the caller program should call
CACHALOT_CAUSE
(andCACHALOT_MSG
) to insert the error into cachalot and then return err to the upper calling function. - Depending on the context, the upper calling function should call
CACHALOT_TRACE
,CACHALOT_WRAP
orCACHALOT_MSG
and then return err to the upper calling function. - Finally,
main
function receive the error and callCACHALOT_STRINGLIZE
to generate the error stack string, print or logging, and exit.