Even though Rust does not have an exception mechanism designed for general error-handling usage, panicking is not far from it. Panics are non-recoverable errors that crash your thread. If the current thread is the main one, then the whole program crashes.
On a more technical level, panicking happens in the same process as exceptions: unwinding the call stack. This means climbing up and out of the place in the code where the panicking happened till hitting the top, at which point, the thread in question aborts. Here's an example where we have two call stacks:
- f1 spawns a new thread and calls f2, which calls f3, which panics
- main calls f2, which calls f3, which panics
Take a look at the following code snippet:
// panic.rs use std::thread; ...