Module rust_examples::errors[][src]

Expand description

This module presents several possibilities of how to handle errors in Rust.

In general, there are two kinds of errors:

  1. Recoverable errors - those are contexts in which there is a possibility to react and correct the situation (e.g. by substituing default value or calling error handler)
  2. Unrecoverable errors - these are unexpected situations which cannot be handled by an application or library resulting in a crash of the program

Naturally, Rust promotes types like Option and Result to mitigate the amount of possible non-recoverable situations.

Functions

This version of division is somewhat artificial but demonstrates another error context, the Result.

This version of division models the error case (d = 0) by an Option.

This function computes num / d in a naive way that causes the program to panic if d = 0