Created
February 7, 2025 15:30
-
-
Save wbbradley/171f826fa938f76043e3e4b05dbe7a80 to your computer and use it in GitHub Desktop.
Example of panic! inside a thread in Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main() { | |
| let x = std::thread::spawn(|| { | |
| std::thread::sleep(std::time::Duration::from_secs(1)); | |
| panic!("I am crashing!"); | |
| }) | |
| .join(); | |
| println!("This result should not be visible! {x:?}"); | |
| } | |
| /// This program's output: | |
| /// | |
| /// thread '<unnamed>' panicked at src/main.rs:4:9: | |
| /// I am crashing! | |
| /// note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace | |
| /// This result should not be visible! Err(Any { .. }) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment