[][src]Crate handle_error

An error handling / bubbling macro to reduce error handling boilerplate.

For a given fallible expression (expression returning a result), such as:

fn do_something() -> Result<(), E> {
    // ....
}

This can be used as follows:

#[macro_use]
extern crate log;
 
#[macro_use]
extern crate handle_error;
 
fn main() -> Result<(), E> {
  let v = handle_error!(do_something(), "Failed to do something");
  Ok(())
}

Replacing the common patterns:

#[macro_use]
extern crate log;
 
#[macro_use]
extern crate handle_error;
 
// Match case where we care about the ok value
fn example_one() -> Result<(), E> {
  let v = match do_something() {
    Ok(v) => v,
    Err(e) => {
      error!("Failed to do something");
      return Err(e);
    }
  };
 
  Ok(())
}
 
// If let where we do not care about the ok value
fn example_two() -> Result<(), E> {
  if let Err(e) = do_something() {
    error!("Failed to do something");
    return Err(e);
  }
 
  Ok(())
}
 

Macros

handle_error

Log and propagate the error result from a given expression