1#![cfg(feature = "alloc")]
2
3use alloc::boxed::Box;
4use core::fmt::{self, Display};
5
6#[cfg(error_in_core)]
7use core::error::Error as StdError;
8#[cfg(all(feature = "std", not(error_in_core)))]
9use std::error::Error as StdError;
10
11#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
13#[derive(Debug)]
14pub struct Exception {
15 pub(crate) what: Box<str>,
16}
17
18impl Display for Exception {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 f.write_str(&self.what)
21 }
22}
23
24#[cfg(any(error_in_core, feature = "std"))]
25impl StdError for Exception {}
26
27impl Exception {
28 #[allow(missing_docs)]
29 pub fn what(&self) -> &str {
30 &self.what
31 }
32}