Location
https://doc.rust-lang.org/beta/core/panic/struct.PanicInfo.html#method.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 |
|
/// |
|
/// ```should_panic |
|
/// 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"); |
|
/// ``` |
|
#[must_use] |
|
#[stable(feature = "panic_hooks", since = "1.10.0")] |
|
pub fn location(&self) -> Option<&Location<'_>> { |
|
// NOTE: If this is changed to sometimes return None, |
|
// deal with that case in std::panicking::default_hook and core::panicking::panic_fmt. |
|
Some(&self.location) |
|
} |
Summary
since #115974 the PanicInfo and PanicHookInfo structs have been split up, but the docs for PanicInfo still show how to use it with a panic hook, even though it is now exclusively for the #[panic_handler] and the panic hook functionality has been moved into PanicHookInfo
Location
https://doc.rust-lang.org/beta/core/panic/struct.PanicInfo.html#method.location
rust/library/core/src/panic/panic_info.rs
Lines 65 to 95 in 9bad7ba
Summary
since #115974 the
PanicInfoandPanicHookInfostructs have been split up, but the docs forPanicInfostill show how to use it with a panic hook, even though it is now exclusively for the#[panic_handler]and the panic hook functionality has been moved intoPanicHookInfo