blob: 2ae470e766c3beb8e3e0bbc035ba5ea75ace63f2 [file] [log] [blame]
David Tolnayc5a52f92020-09-14 00:43:29 -04001use alloc::boxed::Box;
David Tolnay48c01a62021-04-16 00:25:53 -07002use core::fmt::{self, Display};
David Tolnayebef4a22020-03-17 15:33:47 -07003
David Tolnayc72a9f62020-11-11 10:56:26 -08004/// Exception thrown from an `extern "C++"` function.
David Tolnayeedf7372020-05-22 11:08:50 -07005#[derive(Debug)]
David Tolnayebef4a22020-03-17 15:33:47 -07006pub struct Exception {
7 pub(crate) what: Box<str>,
8}
9
10impl Display for Exception {
11 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
12 f.write_str(&self.what)
13 }
14}
15
16impl std::error::Error for Exception {}
17
18impl Exception {
David Tolnaycb07a842021-04-16 16:08:52 -070019 #[allow(missing_docs)]
David Tolnayebef4a22020-03-17 15:33:47 -070020 pub fn what(&self) -> &str {
21 &self.what
22 }
23}