pub struct Error { /* private fields */ }
Expand description
An error that occurs during launch.
An Error
is returned by launch()
when launching an
application fails or, more rarely, when the runtime fails after launching.
Panics
A value of this type panics if it is dropped without first being inspected.
An inspection occurs when any method is called. For instance, if
println!("Error: {}", e)
is called, where e: Error
, the Display::fmt
method being called by println!
results in e
being marked as inspected;
a subsequent drop
of the value will not result in a panic. The following
snippet illustrates this:
if let Err(error) = rocket::build().launch().await {
// This println "inspects" the error.
println!("Launch failed! Error: {}", error);
// This call to drop (explicit here for demonstration) will do nothing.
drop(error);
}
When a value of this type panics, the corresponding error message is pretty printed to the console. The following illustrates this:
let error = rocket::build().launch().await;
// This call to drop (explicit here for demonstration) will result in
// `error` being pretty-printed to the console along with a `panic!`.
drop(error);
Usage
An Error
value should usually be allowed to drop
without inspection.
There are at least two exceptions:
-
If you are writing a library or high-level application on-top of Rocket, you likely want to inspect the value before it drops to avoid a Rocket-specific
panic!
. This typically means simply printing the value. -
You want to display your own error messages.
Implementations§
source§impl Error
impl Error
sourcepub fn kind(&self) -> &ErrorKind
pub fn kind(&self) -> &ErrorKind
Retrieve the kind
of the launch error.
Example
use rocket::error::ErrorKind;
if let Err(error) = rocket::build().launch().await {
match error.kind() {
ErrorKind::Io(e) => println!("found an i/o launch error: {}", e),
e => println!("something else happened: {}", e)
}
}