macro_rules! show {
    ($err:expr) => { ... };
}
Expand description

Display a crate::error::UError and set global exit code.

Prints the error message contained in an crate::error::UError to stderr and sets the exit code through crate::error::set_exit_code. The printed error message is prepended with the calling utility’s name. A call to this macro will not finish program execution.

Examples

The following example would print a message “Some error occurred” and set the utility’s exit code to 2.


use uucore::error::{self, USimpleError};

fn main() {
    let err = USimpleError::new(2, "Some error occurred.");
    show!(err);
    assert_eq!(error::get_exit_code(), 2);
}

If not using crate::error::UError, one may achieve the same behavior like this:


use uucore::error::set_exit_code;

fn main() {
    set_exit_code(2);
    show_error!("Some error occurred.");
}