ccgsl  1.16.1
gsl::exception Class Reference

This class is used to handle gsl exceptions so that gsl can use these rather than the GSL error handling. More...

#include <exception.hpp>

Collaboration diagram for gsl::exception:
Collaboration graph

Public Types

enum  {
  GSL_SUCCESS = 0, GSL_FAILURE = -1, GSL_CONTINUE = -2, GSL_EDOM = 1,
  GSL_ERANGE = 2, GSL_EFAULT = 3, GSL_EINVAL = 4, GSL_EFAILED = 5,
  GSL_EFACTOR = 6, GSL_ESANITY = 7, GSL_ENOMEM = 8, GSL_EBADFUNC = 9,
  GSL_ERUNAWAY = 10, GSL_EMAXITER = 11, GSL_EZERODIV = 12, GSL_EBADTOL = 13,
  GSL_ETOL = 14, GSL_EUNDRFLW = 15, GSL_EOVRFLW = 16, GSL_ELOSS = 17,
  GSL_EROUND = 18, GSL_EBADLEN = 19, GSL_ENOTSQR = 20, GSL_ESING = 21,
  GSL_EDIVERGE = 22, GSL_EUNSUP = 23, GSL_EUNIMPL = 24, GSL_ECACHE = 25,
  GSL_ETABLE = 26, GSL_ENOPROG = 27, GSL_ENOPROGJ = 28, GSL_ETOLF = 29,
  GSL_ETOLX = 30, GSL_ETOLG = 31, GSL_EOF = 32
}
 Enumerated type. More...
 

Public Member Functions

 exception (char const *reason, char const *file, int line, int gsl_errno)
 The constructor takes the same paramters as a GSL error handler: a description of the reason for the error, a file name, a line number, and an error number. More...
 
char const * get_reason () const
 Get the message explaining the reason for the error/exception. More...
 
char const * get_file () const
 Get the name of the file that caused an exception. More...
 
int get_line () const
 Get the line number at which a GSL error handler caused the exception. More...
 
int get_gsl_errno () const
 Get an error number. More...
 
char const * strerror () const
 Get a standard GSL message corresponding to the error number. More...
 

Static Public Member Functions

static void enable ()
 Set the handler function to handle exceptions. More...
 

Static Public Attributes

static void(*)(char const *, char const *, int, int) set_handler (void(*handler)(char const *, char const *, int, int))
 Set the handler function. More...
 
static void(*)(char const *, char const *, int, int) set_handler_gsl_exceptions ()
 Set the handler function to handle exceptions. More...
 
static void(*)(char const *, char const *, int, int) set_handler_off ()
 Set the handler function to a null handler. More...
 

Static Private Member Functions

static void handler_gsl_exceptions (char const *reason, char const *file, int line, int gsl_errno)
 The default exception handler for gsl. More...
 
static void handler_off (char const *, char const *, int, int)
 The empty exception handler for gsl. More...
 

Private Attributes

char const * reason
 A message giving a reason for this exception. More...
 
char const * file
 The file that cause this exception. More...
 
int const line
 The line number in file at which exception handler was called. More...
 
int const gsl_errno
 A number indicating error type. More...
 

Detailed Description

This class is used to handle gsl exceptions so that gsl can use these rather than the GSL error handling.

It defines its own error handler that throws exceptions. But the default behaviour is to rely on the error handling of GSL. Typically C++ users should use

early in their programmes to enable exception handling. Then if a GSL function calls the error handler, you should put this function in a try block and catch gsl::exception objects.

To enable and catch the exceptions, use code like the following.

#include<ccgsl/gsl_exception>
...
gsl::exception::enable();
...
try {
...
} catch( gsl::exception& e ){
...
}

The gsl default handler prints a short message to std::clog. You can change this by deriving your own subclass of exception, say my_exception and create a function, say

void
exception::my_handler( char const* reason, char const* file,
int line, int gsl_errno ){
throw my_exception( reason, file, line, gsl_errno );
}

Then use

instead of

so that GSL uses your handler to create exceptions of class my_exception.

Definition at line 120 of file exception.hpp.

Member Enumeration Documentation

anonymous enum

Enumerated type.

Enumerator
GSL_SUCCESS 
GSL_FAILURE 
GSL_CONTINUE 

iteration has not converged

GSL_EDOM 

input domain error, e.g sqrt(-1)

GSL_ERANGE 

output range error, e.g.

exp(1e100)

GSL_EFAULT 

invalid pointer

GSL_EINVAL 

invalid argument supplied by user

GSL_EFAILED 

generic failure

GSL_EFACTOR 

factorization failed

GSL_ESANITY 

sanity check failed - shouldn't happen

GSL_ENOMEM 

malloc failed

GSL_EBADFUNC 

problem with user-supplied function

GSL_ERUNAWAY 

iterative process is out of control

GSL_EMAXITER 

exceeded max number of iterations

GSL_EZERODIV 

tried to divide by zero

GSL_EBADTOL 

user specified an invalid tolerance

GSL_ETOL 

failed to reach the specified tolerance

GSL_EUNDRFLW 

underflow

GSL_EOVRFLW 

overflow

GSL_ELOSS 

loss of accuracy

GSL_EROUND 

failed because of roundoff error

GSL_EBADLEN 

matrix, vector lengths are not conformant

GSL_ENOTSQR 

matrix not square

GSL_ESING 

apparent singularity detected

GSL_EDIVERGE 

integral or series is divergent

GSL_EUNSUP 

requested feature is not supported by the hardware

GSL_EUNIMPL 

requested feature not (yet) implemented

GSL_ECACHE 

cache limit exceeded

GSL_ETABLE 

table limit exceeded

GSL_ENOPROG 

iteration is not making progress towards solution

GSL_ENOPROGJ 

jacobian evaluations are not improving the solution

GSL_ETOLF 

cannot reach the specified tolerance in F

GSL_ETOLX 

cannot reach the specified tolerance in X

GSL_ETOLG 

cannot reach the specified tolerance in gradient

GSL_EOF 

end of file

Definition at line 201 of file exception.hpp.

Constructor & Destructor Documentation

gsl::exception::exception ( char const *  reason,
char const *  file,
int  line,
int  gsl_errno 
)
inline

The constructor takes the same paramters as a GSL error handler: a description of the reason for the error, a file name, a line number, and an error number.

Parameters
reasonA message explaining the reason for the exception
fileThe name of the file that called the error handler and so created the exception
lineThe line number within file
gsl_errnoAn error number corresponding to the enum below

Definition at line 131 of file exception.hpp.

References reason, and strerror().

Referenced by handler_gsl_exceptions().

Member Function Documentation

static void gsl::exception::enable ( )
inlinestatic

Set the handler function to handle exceptions.

Use set_handler_gsl_exceptions if you want a pointer to the old handler.

Definition at line 185 of file exception.hpp.

References set_handler_gsl_exceptions.

char const* gsl::exception::get_file ( ) const
inline

Get the name of the file that caused an exception.

Returns
the name of the file that caused an exception

Definition at line 154 of file exception.hpp.

References file.

int gsl::exception::get_gsl_errno ( ) const
inline

Get an error number.

Returns
an error number
See also
strerror().

Definition at line 165 of file exception.hpp.

References gsl_errno.

int gsl::exception::get_line ( ) const
inline

Get the line number at which a GSL error handler caused the exception.

Returns
the line number at which a GSL error handler caused the exception

Definition at line 159 of file exception.hpp.

References line.

char const* gsl::exception::get_reason ( ) const
inline

Get the message explaining the reason for the error/exception.

Returns
the message explaining the reason for the error/exception

Definition at line 149 of file exception.hpp.

References reason.

static void gsl::exception::handler_gsl_exceptions ( char const *  reason,
char const *  file,
int  line,
int  gsl_errno 
)
inlinestaticprivate

The default exception handler for gsl.

Parameters
reasonA message explaining the reason for the exception
fileThe name of the file that called the error handler and so created the exception
lineThe line number within file
gsl_errnoAn error number corresponding to the enum below

Definition at line 247 of file exception.hpp.

References exception().

static void gsl::exception::handler_off ( char const *  ,
char const *  ,
int  ,
int   
)
inlinestaticprivate

The empty exception handler for gsl.

Definition at line 252 of file exception.hpp.

char const* gsl::exception::strerror ( ) const
inline

Get a standard GSL message corresponding to the error number.

Returns
a standard GSL message corresponding to the error number

Definition at line 170 of file exception.hpp.

References gsl_errno.

Referenced by exception().

Member Data Documentation

char const* gsl::exception::file
private

The file that cause this exception.

Definition at line 261 of file exception.hpp.

Referenced by get_file().

int const gsl::exception::gsl_errno
private

A number indicating error type.

See also
strerror()

Definition at line 270 of file exception.hpp.

Referenced by get_gsl_errno(), and strerror().

int const gsl::exception::line
private

The line number in file at which exception handler was called.

Definition at line 265 of file exception.hpp.

Referenced by get_line().

char const* gsl::exception::reason
private

A message giving a reason for this exception.

Definition at line 257 of file exception.hpp.

Referenced by exception(), and get_reason().

void(*)( char const*, char const*, int, int ) gsl::exception::set_handler(void(*handler)(char const *, char const *, int, int))
inlinestatic

Set the handler function.

This corresponds to gsl_set_error_handler and allows you to set your own error handler. Note that ccgsl provides a default error handler that throws exceptions of class exception.

Parameters
handlerThe new handler
Returns
A pointer to the old handler

Definition at line 179 of file exception.hpp.

void(*)( char const*, char const*, int, int ) gsl::exception::set_handler_gsl_exceptions()
inlinestatic

Set the handler function to handle exceptions.

Returns
A pointer to the old handler

Definition at line 190 of file exception.hpp.

Referenced by enable().

void(*)( char const*, char const*, int, int ) gsl::exception::set_handler_off()
inlinestatic

Set the handler function to a null handler.

This disables any error handling.

Returns
A pointer to the old handler

Definition at line 196 of file exception.hpp.


The documentation for this class was generated from the following file: