Overview

Dealing with errors is a key aspect of any language. Good error handling allows you to write reliable code that is prepared for errors and can respond correctly to them.

There are no exceptions in Spawn. Instead, there are two different types of errors, recoverable and unrecoverable (panics). Recoverable errors are errors that occur in a program when something goes wrong — for example, when opening a file that doesn't exist or trying to parse invalid JSON.

Unrecoverable errors represent bugs in the program, for example, if you go beyond the bounds of an array or divide a number by zero.

Spawn uses the Result and Option types to represent recoverable errors, and the panic function to represent unrecoverable errors.

We'll look at unrecoverable errors first, and then recoverable ones.