ferroui_splat/logging/
logging_exception.rs1use std::error::Error;
4use std::fmt;
5
6#[derive(Debug)]
12pub struct LoggingException {
13 message: String,
14 inner: Option<Box<dyn Error + Send + Sync>>,
15}
16
17impl LoggingException {
18 pub fn new() -> Self {
20 Self { message: "Exception of type 'LoggingException' was thrown.".to_owned(), inner: None }
21 }
22
23 pub fn with_message(message: impl Into<String>) -> Self {
25 Self { message: message.into(), inner: None }
26 }
27
28 pub fn with_inner(message: impl Into<String>, inner_exception: Box<dyn Error + Send + Sync>) -> Self {
31 Self { message: message.into(), inner: Some(inner_exception) }
32 }
33
34 pub fn message(&self) -> &str {
36 &self.message
37 }
38
39 pub fn inner_exception(&self) -> Option<&(dyn Error + Send + Sync + 'static)> {
41 self.inner.as_deref()
42 }
43}
44
45impl Default for LoggingException {
46 fn default() -> Self {
47 Self::new()
48 }
49}
50
51impl fmt::Display for LoggingException {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 f.write_str(&self.message)
54 }
55}
56
57impl Error for LoggingException {
58 fn source(&self) -> Option<&(dyn Error + 'static)> {
59 self.inner.as_deref().map(|inner| inner as &(dyn Error + 'static))
60 }
61}