preserve_panic_message/
preserve_panic_message.rs

1
2extern crate easycurses;
3
4use easycurses::*;
5
6fn main() {
7    // We wrap all our use of curses with this function.
8    preserve_panic_message(|easy| {
9        // In here we get an initialized EasyCurses handle and then proceed to
10        // use it exactly like we normally would use it.
11        easy.set_cursor_visibility(CursorVisibility::Invisible);
12        easy.set_echo(false);
13        easy.print("Hello world.");
14        easy.refresh();
15        easy.get_input();
16        panic!("oh no");
17    }).unwrap_or_else(|e| match e {
18        // This block only runs if there was an error. We might or might not
19        // have been able to recover an error message. You technically can pass
20        // any value into a panic, but we only get an error message if the panic
21        // value was a `String` or `&str`.
22        Some(errmsg) => println!("Error Occurred: {}", errmsg),
23        None => println!("There was an error, but no error message."),
24    });
25}