diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2019-09-04 13:00:14 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2019-09-09 08:20:34 -0700 |
| commit | 34662c69614028944668f96c91ef294e7da048f0 (patch) | |
| tree | 2bcb69599dfd9ad63c623f69328ee533db8ee212 /src/libstd/error.rs | |
| parent | 824383d4ab66abd32abc6e19b68d78ecfddcb7d4 (diff) | |
| download | rust-34662c69614028944668f96c91ef294e7da048f0.tar.gz rust-34662c69614028944668f96c91ef294e7da048f0.zip | |
std: Add a `backtrace` module
This commit adds a `backtrace` module to the standard library, as designed in [RFC 2504]. The `Backtrace` type is intentionally very conservative, effectively only allowing capturing it and printing it. Additionally this commit also adds a `backtrace` method to the `Error` trait which defaults to returning `None`, as specified in [RFC 2504]. More information about the design here can be found in [RFC 2504] and in the [tracking issue]. Implementation-wise this is all based on the `backtrace` crate and very closely mirrors the `backtrace::Backtrace` type on crates.io. Otherwise it's pretty standard in how it handles everything internally. [RFC 2504]: https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md [tracking issue]: https://github.com/rust-lang/rust/issues/53487 cc #53487
Diffstat (limited to 'src/libstd/error.rs')
| -rw-r--r-- | src/libstd/error.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 117a430eec6..998d59f90a2 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -17,6 +17,7 @@ use core::array; use crate::alloc::{AllocErr, LayoutErr, CannotReallocInPlace}; use crate::any::TypeId; +use crate::backtrace::Backtrace; use crate::borrow::Cow; use crate::cell; use crate::char; @@ -204,6 +205,20 @@ pub trait Error: Debug + Display { fn type_id(&self, _: private::Internal) -> TypeId where Self: 'static { TypeId::of::<Self>() } + + /// Returns a stack backtrace, if available, of where this error ocurred. + /// + /// This function allows inspecting the location, in code, of where an error + /// happened. The returned `Backtrace` contains information about the stack + /// trace of the OS thread of execution of where the error originated from. + /// + /// Note that not all errors contain a `Backtrace`. Also note that a + /// `Backtrace` may actually be empty. For more information consult the + /// `Backtrace` type itself. + #[unstable(feature = "backtrace", issue = "53487")] + fn backtrace(&self) -> Option<&Backtrace> { + None + } } mod private { |
