Function rgsl::error::set_error_handler[][src]

pub fn set_error_handler(
    f: Option<fn(_: &str, _: &str, _: u32, _: Value)>
) -> Option<fn(_: &str, _: &str, _: u32, _: Value)>
Expand description

f is the type of GSL error handler functions. An error handler will be passed four arguments which specify the reason for the error (a string), the name of the source file in which it occurred (also a string), the line number in that file (an integer) and the error number (an integer). The source file and line number are set at compile time using the FILE and LINE directives in the preprocessor. An error handler function returns type void. Error handler functions should be defined like this,

This function sets a new error handler, new_handler, for the GSL library routines. The previous handler is returned (so that you can restore it later). Note that the pointer to a user defined error handler function is stored in a static variable, so there can be only one error handler per program. This function should be not be used in multi-threaded programs except to set up a program-wide error handler from a master thread. The following example shows how to set and restore a new error handler,

use rgsl::error::set_error_handler;
use rgsl::Value;

fn error_handling(error_str: &str, file: &str, line: u32, error_value: Value) {
    println!("[{:?}] '{}:{}': {}", error_value, file, line, error_str);
}

/* save original handler, install new handler */
let old_handler = set_error_handler(Some(error_handling));

/* code uses new handler */
// ...

/* restore original handler */
set_error_handler(old_handler);

To use the default behavior (abort on error) set the error handler to NULL,

let old_handler = set_error_handler(None);