pub struct BevyError { /* private fields */ }Expand description
The built in “universal” Bevy error type. This has a blanket From impl for any type that implements Rust’s Error,
meaning it can be used as a “catch all” error.
§Severity
Each BevyError carries a Severity value that indicates how serious the error is.
While the levels within Severity correspond to traditional logging levels,
these levels are fundamentally advisory metadata.
The fallback error handler ultimately has discretion to respond to each of these errors
according to its configuration.
The error handler ultimately has discretion to respond to each of these errors according to its configuration.
You can change the behavior of the fallback handler by modifying the FallbackErrorHandler resource.
By default, errors without an assigned severity use Severity::Panic, and will cause your application to panic.
You can change the severity of an error by using with_severity, or map_severity on any Result type.
§Backtraces
When used with the backtrace Cargo feature, it can capture a backtrace when the error is constructed (generally in the From impl).
To enable backtrace capture on supported platforms,
set the RUST_BACKTRACE environment variable.
See Backtrace::capture for details.
When the error is printed, the backtrace will be displayed.
By default, the backtrace will be trimmed down to filter out noise.
To see the full backtrace, set the BEVY_BACKTRACE=full environment variable.
§Usage
fn fallible_system() -> Result<(), BevyError> {
// This will result in Rust's built-in ParseIntError, which will automatically
// be converted into a BevyError.
let parsed: usize = "I am not a number".parse()?;
Ok(())
}Implementations§
Source§impl BevyError
impl BevyError
Sourcepub fn new<E>(severity: Severity, error: E) -> Self
pub fn new<E>(severity: Severity, error: E) -> Self
Constructs a new BevyError with the given Severity.
The error will be stored as a Box<dyn Error + Send + Sync>.
The easiest way to use this is to pass in a string.
This works because any type that can be converted into a Box<dyn Error + Send + Sync> can be used,
and str is one such type.
§Examples
fn some_function(val: i64) -> Result<(), BevyError> {
if val < 0 {
let error =
BevyError::new(Severity::Panic, format!("Value can't be negative {val}"));
return Err(error);
}
// ...
Ok(())
}Sourcepub fn ignore<E>(error: E) -> Self
pub fn ignore<E>(error: E) -> Self
Creates a new BevyError with the Severity::Ignore severity.
This is a shorthand for BevyError::new(Severity::Ignore, error).
Sourcepub fn trace<E>(error: E) -> Self
pub fn trace<E>(error: E) -> Self
Creates a new BevyError with the Severity::Trace severity.
This is a shorthand for BevyError::new(Severity::Trace, error).
Sourcepub fn debug<E>(error: E) -> Self
pub fn debug<E>(error: E) -> Self
Creates a new BevyError with the Severity::Debug severity.
This is a shorthand for BevyError::new(Severity::Debug, error).
Sourcepub fn info<E>(error: E) -> Self
pub fn info<E>(error: E) -> Self
Creates a new BevyError with the Severity::Info severity.
This is a shorthand for BevyError::new(Severity::Info, error).
Sourcepub fn warning<E>(error: E) -> Self
pub fn warning<E>(error: E) -> Self
Creates a new BevyError with the Severity::Warning severity.
This is a shorthand for BevyError::new(Severity::Warning, error).
Sourcepub fn error<E>(error: E) -> Self
pub fn error<E>(error: E) -> Self
Creates a new BevyError with the Severity::Error severity.
This is a shorthand for BevyError::new(Severity::Error, error).
Sourcepub fn panic<E>(error: E) -> Self
pub fn panic<E>(error: E) -> Self
Creates a new BevyError with the Severity::Panic severity.
This is a shorthand for BevyError::new(Severity::Panic, error).
Sourcepub fn is<E: Error + 'static>(&self) -> bool
pub fn is<E: Error + 'static>(&self) -> bool
Checks if the internal error is of the given type.
Sourcepub fn downcast_ref<E: Error + 'static>(&self) -> Option<&E>
pub fn downcast_ref<E: Error + 'static>(&self) -> Option<&E>
Attempts to downcast the internal error to the given type.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BevyError
impl !RefUnwindSafe for BevyError
impl Send for BevyError
impl Sync for BevyError
impl Unpin for BevyError
impl UnsafeUnpin for BevyError
impl !UnwindSafe for BevyError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.