pub struct PanicInfo<'a> { /* private fields */ }Expand description
A struct providing information about a panic.
A PanicInfo structure is passed to the panic handler defined by #[panic_handler].
For the type used by the panic hook mechanism in std, see std::panic::PanicHookInfo.
Implementations§
Source§impl<'a> PanicInfo<'a>
impl<'a> PanicInfo<'a>
1.10.0 · Sourcepub fn location(&self) -> Option<&Location<'_>>
pub fn location(&self) -> Option<&Location<'_>>
Returns information about the location from which the panic originated, if available.
This method will currently always return Some, but this may change
in future versions.
§Examples
ⓘ
use std::panic;
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(),
);
} else {
println!("panic occurred but can't get location information...");
}
}));
panic!("Normal panic");