For fatal error handling, I'm using the panic!
macro, but I would prefer to have a macro that did not print the file/line information, only the error message.
I read the macro documentation, but my understanding is a bit shaky.
I looked at the source of the panic!
macro, but it's calling functions to do its work where the file and line information is an integral part of the operation, so I can't just tweak that.
I looked at the println!
macro, which looks more promising, but I have two problems I an unaware of how to solve.
macro_rules! die {
() => (print!("\n"));
($fmt:expr) => (print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*); exit(-1));
}
If I put the exit()
call in, as I have on the last line, I get syntax errors when trying to call it.
If I remove the exit()
, I don't get complaints about the macro, but this code fails to compile:
let file = match File::open(&path) {
Err(why) => die!("Couldn't open {}: {}", display, why.description()),
Ok(file) => file,
};
Whereas it does compile when die!
is replaced with panic!
. I assume there is some magic about panic!
which tells the compiler that it never returns?