Errors usually fall into two categories, recoverable and unrecoverable.
Languages like Rust and Go handle recoverable errors by returning special
A function unable to return valid values may throw an exception that encodes the cause of the error. This is the prefered way of handling errors in languages like C++ and D.
Most languages provide a mechanism to signal an error and immediately
terminate the program. In Rust this is achieved by using the
panic! macro. The program then will print a failure message,
clean up the stack and exit. In C and C++ you can use the
exit function. Rust also has an
panic! is prefered.
Functions are free to ignore errors, and they will bubble up all the way to the main function. An unhandled error will terminate the program with a non-zero exit code.
Errors are handled by the
>! operator or the equivalent
catch function. The error handler must return the same type as
the previous statement in the stream, or rethrow the error.