Robustness & Error Handling

The Wolfram Language provides a variety of mechanisms for detecting and managing errors and for helping ensure that programs are robust and operate as intended. The Confirm family of functions allows various forms of error conditions to be checked during the execution of a program, with program execution immediately terminated when errors are detected. Enclose defines the scope in a program in which errors will be caught.

Function Argument Checking

CheckArguments check the structure of function arguments

Condition (/;) require a pattern or definition to satisfy a condition

ArgumentsOptions  ▪  OptionsPattern

Runtime Error Handling

Confirm evaluate an expression, confirming that no failure is generated

Enclose evaluate an expression, stopping and returning a failure object if a failure occurs

WithCleanup run cleanup code even if an evaluation is interrupted

Types of Confirmation

ConfirmBy evaluate an expression, confirming that the result satisfies a condition

ConfirmMatch evaluate an expression, confirming that the result matches a pattern

ConfirmQuiet evaluate an expression, confirming that no messages are generated

ConfirmAssert confirm that an assertion is satisfied

Failure Representation

Failure  ▪  Missing  ▪  $Failed  ▪  TerminatedEvaluation

Code Monitoring

Assert abort if a condition is not satisfied

Interrupt  ▪  Abort

Echo print an intermediate result

EchoEvaluation  ▪  EchoTiming  ▪  EchoFunction  ▪  EchoLabel

Low-Level Error Handling

Check  ▪  CheckAbort  ▪  AbortProtect  ▪  PropagateAborts

Throw  ▪  Catch