[][src]Macro molt::molt_err

macro_rules! molt_err {
    ($arg:expr) => { ... };
    ($($arg:tt)*) => { ... };
}

Returns an Error MoltResult. The error message is formatted as with format!().

If called with one argument, the single argument is used as the error message. If called with more than one argument, the first is a format!() format string, and the remainder are the values to format.

This macro wraps the Exception::molt_err method.

Examples

use molt::*;

// Return a simple error message
fn err1() -> MoltResult {
    // ...
    molt_err!("error message")
}

let result = err1();
assert!(result.is_err());

let exception = result.err().unwrap();
assert!(exception.is_error());
assert_eq!(exception.value(), "error message".into());

// Return a formatted error
fn err2() -> MoltResult {
   // ...
   molt_err!("invalid value: {}", 17)
}

let result = err2();
assert!(result.is_err());

let exception = result.err().unwrap();
assert!(exception.is_error());
assert_eq!(exception.value(), "invalid value: 17".into());