1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-06 09:37:27 +02:00

22 lines
491 B
Markdown
Raw Normal View History

2022-12-21 16:36:30 +01:00
# Catching the Stack Unwinding
By default, a panic will cause the stack to unwind. The unwinding can be caught:
```rust
use std::panic;
let result = panic::catch_unwind(|| {
println!("hello!");
});
assert!(result.is_ok());
let result = panic::catch_unwind(|| {
panic!("oh no!");
});
assert!(result.is_err());
```
* This can be useful in servers which should keep running even if a single
request crashes.
2023-01-20 04:28:38 -06:00
* This does not work if `panic = 'abort'` is set in your `Cargo.toml`.