this section defines a structured model for categorizing error-handling strategies using a multi-dimensional tuple system. each strategy is described by the interaction of key properties such as signal form, error content, control flow, and propagation scope.
each error-handling pattern is described as a 5-tuple:
(signal, content, control, propagation, binding)
signal: how the presence of an error is indicated
content: what information is attached to the error
control: what control mechanism is used to handle errors
propagation: how errors move through the call chain
binding: how error-handling logic is connected to the call
process exit code
(status-value, code, inline-check, explicit, global)
designated return value
(designated-value, none, inline-check, explicit, manual)
status + output values
(multiple-values, code, inline-check, explicit, manual)
error object return
(multiple-values, structured, inline-check, reified, manual)
structured error with macros
(status-value, structured, local-jump, explicit, protocol)
exception handling
(exception, structured, non-local-jump, implicit, handler)
continuation passing
(continuation, structured, continuation, implicit, handler)
global error flag
(global-flag, code, passive, implicit, global)
before implementation begins, a developer should explicitly select an error-handling strategy. failing to do so often leads to code in which failures are inconsistently handled, hard to trace, difficult to recover from, or not handled at all. ad-hoc mechanisms that have been woven-in into large codebases resist harmonization.
subroutines typically have a primary goal-e.g. dividing two numbers or writing to a file. this goal can fail due to:
some systems use specific types or values to indicate failure:
false
, null
, or empty stringsome subroutines return a default or neutral value (e.g. 0
, empty array) in place of a real result when failing.
pros:
if length == 0
)0
a result or a signal of failure?error status may be returned separately from the actual result. for example:
input, output, -> status
instead of:
input, -> (output, status)
notes:
two common forms:
errors are detected and control jumps to a local cleanup or handler section within the same function. pros:
errors exit the current call context and propagate up the stack until a handler is reached. pros:
some systems set a global or thread-local error variable (e.g. errno
).
cons:
typical fields for detailed error representation include:
error-name error-description source-routine-name source-line-number source-file source-module-name backtrace literal-irritant-expression
0
means success; any other code indicates failuremkdir new_directory && cd new_directory
-1
, null
, or special constants on errorerrno
holds the associated codesph-sc-lib uses a status
struct with an integer id and group string, along with helper macros to propagate and branch on error:
int main() { status_declare; // code ... status_require(test()); // more code ... exit: return status.id; }