1 #![cfg(feature = "alloc")] 2 3 use alloc::boxed::Box; 4 use core::fmt::{self, Display}; 5 6 /// Exception thrown from an `extern "C++"` function. 7 #[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))] 8 #[derive(Debug)] 9 pub struct Exception { 10 pub(crate) what: Box<str>, 11 } 12 13 impl Display for Exception { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result14 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 15 f.write_str(&self.what) 16 } 17 } 18 19 #[cfg(feature = "std")] 20 #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] 21 impl std::error::Error for Exception {} 22 23 impl Exception { 24 #[allow(missing_docs)] what(&self) -> &str25 pub fn what(&self) -> &str { 26 &self.what 27 } 28 } 29