Skip to content

Instantly share code, notes, and snippets.

@wbbradley
Created February 7, 2025 15:30
Show Gist options
  • Select an option

  • Save wbbradley/171f826fa938f76043e3e4b05dbe7a80 to your computer and use it in GitHub Desktop.

Select an option

Save wbbradley/171f826fa938f76043e3e4b05dbe7a80 to your computer and use it in GitHub Desktop.
Example of panic! inside a thread in Rust
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