Skip to content

Commit a23d8ec

Browse files
authored
Rollup merge of #71480 - GuillaumeGomez:panic-info-example, r=Dylan-DPC
Improve PanicInfo examples readability cc @Eijebong r? @Dylan-DPC
2 parents f3331cb + 03817ec commit a23d8ec

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/libcore/panic.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ impl<'a> PanicInfo<'a> {
7777
/// use std::panic;
7878
///
7979
/// panic::set_hook(Box::new(|panic_info| {
80-
/// println!("panic occurred: {:?}", panic_info.payload().downcast_ref::<&str>().unwrap());
80+
/// if let Some(s) = panic_info.payload().downcast_ref::<&str>() {
81+
/// println!("panic occurred: {:?}", s);
82+
/// } else {
83+
/// println!("panic occurred");
84+
/// }
8185
/// }));
8286
///
8387
/// panic!("Normal panic");
@@ -112,8 +116,10 @@ impl<'a> PanicInfo<'a> {
112116
///
113117
/// panic::set_hook(Box::new(|panic_info| {
114118
/// if let Some(location) = panic_info.location() {
115-
/// println!("panic occurred in file '{}' at line {}", location.file(),
116-
/// location.line());
119+
/// println!("panic occurred in file '{}' at line {}",
120+
/// location.file(),
121+
/// location.line(),
122+
/// );
117123
/// } else {
118124
/// println!("panic occurred but can't get location information...");
119125
/// }

0 commit comments

Comments
 (0)