diff options
Diffstat (limited to 'WebInterface/wasm/webhogg/src/webhogg_exception.rs')
-rw-r--r-- | WebInterface/wasm/webhogg/src/webhogg_exception.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/WebInterface/wasm/webhogg/src/webhogg_exception.rs b/WebInterface/wasm/webhogg/src/webhogg_exception.rs new file mode 100644 index 0000000..46eedd6 --- /dev/null +++ b/WebInterface/wasm/webhogg/src/webhogg_exception.rs @@ -0,0 +1,39 @@ +use std::error::Error; + +#[derive(Debug)] +pub enum WebhoggException { + DomError(String), + WebGlContextError(String), +} + +impl WebhoggException { + fn err_name(&self) -> &str { + match self { + WebhoggException::DomError(_) => "DomError", + WebhoggException::WebGlContextError(_) => "WebGlContextError", + } + } +} + +impl Error for WebhoggException { + fn description(&self) -> &str { + match self { + WebhoggException::DomError(desc) => desc, + WebhoggException::WebGlContextError(desc) => desc, + } + } + + fn cause(&self) -> Option<&dyn Error> { + self.source() + } + + fn source(&self) -> Option<&(dyn Error + 'static)> { + None + } +} + +impl std::fmt::Display for WebhoggException { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "WebhoggException::{} {}", self.err_name(), self.description()) + } +} |