diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-04-25 01:35:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-25 01:35:57 +0200 |
| commit | a23d8ec8a7525ae90e7625312cc2bee83dbb7493 (patch) | |
| tree | 2ecd7e6ae142c06c71ed674615010113521b8f72 /src/libcore | |
| parent | f3331cb5b1aa515b38e6621229edcf0bd2eb9d45 (diff) | |
| parent | 03817ec78917d37d8d41b57029f2fb8e9474108c (diff) | |
| download | rust-a23d8ec8a7525ae90e7625312cc2bee83dbb7493.tar.gz rust-a23d8ec8a7525ae90e7625312cc2bee83dbb7493.zip | |
Rollup merge of #71480 - GuillaumeGomez:panic-info-example, r=Dylan-DPC
Improve PanicInfo examples readability cc @Eijebong r? @Dylan-DPC
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/panic.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs index dbfcbca3ffc..575f51d0a7d 100644 --- a/src/libcore/panic.rs +++ b/src/libcore/panic.rs @@ -77,7 +77,11 @@ impl<'a> PanicInfo<'a> { /// use std::panic; /// /// panic::set_hook(Box::new(|panic_info| { - /// println!("panic occurred: {:?}", panic_info.payload().downcast_ref::<&str>().unwrap()); + /// if let Some(s) = panic_info.payload().downcast_ref::<&str>() { + /// println!("panic occurred: {:?}", s); + /// } else { + /// println!("panic occurred"); + /// } /// })); /// /// panic!("Normal panic"); @@ -112,8 +116,10 @@ impl<'a> PanicInfo<'a> { /// /// panic::set_hook(Box::new(|panic_info| { /// if let Some(location) = panic_info.location() { - /// println!("panic occurred in file '{}' at line {}", location.file(), - /// location.line()); + /// println!("panic occurred in file '{}' at line {}", + /// location.file(), + /// location.line(), + /// ); /// } else { /// println!("panic occurred but can't get location information..."); /// } |
