blob: 0ffca66a36b2b4e83a3532285e3ad8527627c8ea [file] [log] [blame]
David Tolnayc5a52f92020-09-14 00:43:29 -04001use alloc::boxed::Box;
David Tolnay3384c142020-09-14 00:26:47 -04002use core::fmt::{self, Debug, Display};
David Tolnayebef4a22020-03-17 15:33:47 -07003
4/// 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 {
19 pub fn what(&self) -> &str {
20 &self.what
21 }
22}