B.1 Exception handling

GSL provides a selectable error handler, that is called for occuring errors (like domain errors, division by zero, etc. ). pygsl.init installs a handler by calling gsl_set_error_handler to set an appropiate exception from pygsl.errors. A pygsl interface function should return NULL in case of an error, so the exception is raised. If this handler is called more than once before returning to python, only the first set exception is raised.

Here is a python level example:

import pygsl.histogram
import pygsl.errors
hist=pygsl.histogram.histogram2d(100,100)
try:
   hist[-1,-1]=0
except pygsl.errors.gsl_Error,err:
   print err
Will result
input domain error: index i lies outside valid range of 0 .. nx - 1