mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-08 10:36:17 +02:00
Update catch_unwind example (#1356)
Fixes #1352. --------- Co-authored-by: Martin Geisler <martin@geisler.net>
This commit is contained in:
parent
de0e8e6b6d
commit
358d7da22c
@ -7,17 +7,17 @@ use std::panic;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let result = panic::catch_unwind(|| {
|
let result = panic::catch_unwind(|| {
|
||||||
println!("hello!");
|
"No problem here!"
|
||||||
});
|
});
|
||||||
assert!(result.is_ok());
|
println!("{result:?}");
|
||||||
|
|
||||||
let result = panic::catch_unwind(|| {
|
let result = panic::catch_unwind(|| {
|
||||||
panic!("oh no!");
|
panic!("oh no!");
|
||||||
});
|
});
|
||||||
assert!(result.is_err());
|
println!("{result:?}");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* This can be useful in servers which should keep running even if a single
|
- This can be useful in servers which should keep running even if a single
|
||||||
request crashes.
|
request crashes.
|
||||||
* This does not work if `panic = 'abort'` is set in your `Cargo.toml`.
|
- This does not work if `panic = 'abort'` is set in your `Cargo.toml`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user