16. Exceptions and Errors

Legality Rules

16:1 The Rust programming language lacks exceptions and exception handlers. Instead, the language uses the following tiered error handling scheme:

16:5 Enum core::option::Option indicates whether a value is either present using core::option::Option::Some or absent using core::option::Option::None.

16:6 Enum core::result::Result indicates whether a computation completed successfully and produced a value using core::result::Result::Ok or the computation failed with an error using core::result::Result::Err.

16.1. Panic

Legality Rules

16.1:1 A panic is an abnormal program state caused by invoking macro core::panic.

Dynamic Semantics

16.1:2 Invoking macro core::panic has the following runtime effects:

  1. 16.1:3 Control flow halts the execution of the current thread.

  2. 16.1:4 Control flow of the current thread resumes execution by invoking the function subject to attribute panic_handler.

Examples

panic!("This was a terrible mistake!");

16.2. Abort

Legality Rules

16.2:1 Abort is the immediate termination of a program.

Dynamic Semantics

16.2:2 Abort has the following runtime effects:

  1. 16.2:3 Control flow halts the execution of all threads.

  2. 16.2:4 The program terminates.