Function easycurses::preserve_panic_message
[−]
[src]
pub fn preserve_panic_message<F: FnOnce(&mut EasyCurses) -> R + UnwindSafe, R>(
user_function: F
) -> Result<R, Option<String>>
Wraps the use of curses with catch_unwind
to preserve panic info.
Normally, if your program panics while in curses mode the panic message
prints immediately and then is destroyed before you can see it by the
automatic cleanup of curses mode. Instead, this runs the function you pass
it within catch_unwind
and when there's a panic it catches the panic value
and attempts to downcast it into a String
you can print out or log or
whatever you like. Since a panic value can be anything at all this won't
always succeed, thus the Option
wrapper on the Err
case. Regardless of
what of Result
you get back, curses mode will be fully cleaned up and shut
down by the time this function returns.
Note that you don't have to use this if you just want your terminal
restored to normal when your program panics while in curses mode. That is
handled automatically by the Drop
implementation of EasyCurses
. You only
need to use this if you care about the panic message itself.