Error Reporting - GNU Scientific Library -- Reference Manual
Description: GNU Scientific Library -- Reference Manual

Next: Error Codes, Up: Error Handling

### 3.1 Error Reporting

The library follows the thread-safe error reporting conventions of the posix Threads library. Functions return a non-zero error code to indicate an error and `0` to indicate success.

         int status = gsl_function (...)

         if (status) { /* an error occurred */
           .....
           /* status value specifies the type of error */
         }

The routines report an error whenever they cannot perform the task requested of them. For example, a root-finding function would return a non-zero error code if could not converge to the requested accuracy, or exceeded a limit on the number of iterations. Situations like this are a normal occurrence when using any mathematical library and you should check the return status of the functions that you call.

Whenever a routine reports an error the return value specifies the type of error. The return value is analogous to the value of the variable `errno` in the C library. The caller can examine the return code and decide what action to take, including ignoring the error if it is not considered serious.

In addition to reporting errors by return codes the library also has an error handler function `gsl_error`. This function is called by other library functions when they report an error, just before they return to the caller. The default behavior of the error handler is to print a message and abort the program,

         gsl: file.c:67: ERROR: invalid argument supplied by user
         Default GSL error handler invoked.
         Aborted

The purpose of the `gsl_error` handler is to provide a function where a breakpoint can be set that will catch library errors when running under the debugger. It is not intended for use in production programs, which should handle any errors using the return codes.

The GNU Scientific Library - a free numerical library licensed under the GNU GPL
Back to the GNU Scientific Library Homepage