Last active
May 12, 2021 03:25
-
-
Save vmx/5d952e751a7e20b62cd45385bd9fea62 to your computer and use it in GitHub Desktop.
Minimal example for "Printing panics in Rust" blog post
This file contains 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
use std::panic; | |
fn main() { | |
let result = panic::catch_unwind(|| { | |
panic!("Some nice cause for this panic".to_string()); | |
}); | |
if let Err(panic) = result { | |
match panic.downcast::<String>() { | |
Ok(panic_msg) => { | |
println!("panic happened: {}", panic_msg); | |
} | |
Err(_) => { | |
println!("panic happend: unknown type."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment