ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
exception.hpp
Go to the documentation of this file.
1/*
2 * $Id: exception.hpp 247 2012-08-12 11:22:22Z jdl3 $
3 * Copyright (C) 2010, 2020 John D Lamb
4 * Enum copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#ifndef CCGSL_EXCEPTION_HPP
22#define CCGSL_EXCEPTION_HPP
23#include<iostream>
24#include<iso646.h>
25#include<gsl/gsl_errno.h>
26
345namespace gsl {
387 class exception {
388 public:
398 exception( char const* reason, char const* file, int line, int gsl_errno )
400 if( file != 0 ) std::clog << file << ":";
401 if( line != 0 ) std::clog << line << ": ";
402 std::clog << "gsl::exception: ";
403 char const* message = strerror();
404 if( message != 0 )
405 std::clog << message; // << ": ";
406 else
407 std::clog << "undefined error: ";
408 if( reason != 0 )
409 std::clog << ": " << reason;
410 std::clog << std::endl;
411 }
416 char const* get_reason() const { return reason; }
421 char const* get_file() const { return file; }
426 int get_line() const { return line; }
432 int get_gsl_errno() const { return gsl_errno; }
437 char const* strerror() const { return gsl_strerror( gsl_errno ); }
438 public:
446 static void (*set_handler( void (*handler)( char const*, char const*, int, int )))
447 ( char const*, char const*, int, int ){ return gsl_set_error_handler( handler ); }
457 static void (*set_handler_gsl_exceptions())( char const*, char const*, int, int ){
458 return gsl_set_error_handler( handler_gsl_exceptions ); }
463 static void (*set_handler_off())( char const*, char const*, int, int ){
464 return gsl_set_error_handler( handler_off ); }
468 enum {
485 GSL_ETOL = 14,
503 GSL_EOF = 32
504 };
505 private:
514 static void handler_gsl_exceptions( char const* reason, char const* file, int line, int gsl_errno ){
515 throw exception( reason, file, line, gsl_errno ); }
519 static void handler_off( char const*, char const*, int, int ){ /* Do nothing */ }
520 private:
524 char const* reason;
528 char const* file;
532 int const line;
537 int const gsl_errno;
538 };
539
540}
541
542#endif
This class is used to handle gsl exceptions so that gsl can use these rather than the GSL error handl...
Definition: exception.hpp:387
int const gsl_errno
A number indicating error type.
Definition: exception.hpp:537
char const * reason
A message giving a reason for this exception.
Definition: exception.hpp:524
static void(*)(char const *, char const *, int, int) set_handler_off()
Set the handler function to a null handler.
Definition: exception.hpp:463
static void handler_off(char const *, char const *, int, int)
The empty exception handler for gsl.
Definition: exception.hpp:519
char const * get_file() const
Get the name of the file that caused an exception.
Definition: exception.hpp:421
static void(*)(char const *, char const *, int, int) set_handler(void(*handler)(char const *, char const *, int, int))
Set the handler function.
Definition: exception.hpp:446
@ GSL_ENOPROGJ
jacobian evaluations are not improving the solution
Definition: exception.hpp:499
@ GSL_EDOM
input domain error, e.g sqrt(-1)
Definition: exception.hpp:472
@ GSL_ETOLF
cannot reach the specified tolerance in F
Definition: exception.hpp:500
@ GSL_ENOPROG
iteration is not making progress towards solution
Definition: exception.hpp:498
@ GSL_EDIVERGE
integral or series is divergent
Definition: exception.hpp:493
@ GSL_EOVRFLW
overflow
Definition: exception.hpp:487
@ GSL_ELOSS
loss of accuracy
Definition: exception.hpp:488
@ GSL_ETABLE
table limit exceeded
Definition: exception.hpp:497
@ GSL_EFACTOR
factorization failed
Definition: exception.hpp:477
@ GSL_ECACHE
cache limit exceeded
Definition: exception.hpp:496
@ GSL_EOF
end of file
Definition: exception.hpp:503
@ GSL_EZERODIV
tried to divide by zero
Definition: exception.hpp:483
@ GSL_CONTINUE
iteration has not converged
Definition: exception.hpp:471
@ GSL_EMAXITER
exceeded max number of iterations
Definition: exception.hpp:482
@ GSL_EFAILED
generic failure
Definition: exception.hpp:476
@ GSL_ENOTSQR
matrix not square
Definition: exception.hpp:491
@ GSL_ESANITY
sanity check failed - shouldn't happen
Definition: exception.hpp:478
@ GSL_EINVAL
invalid argument supplied by user
Definition: exception.hpp:475
@ GSL_ETOLX
cannot reach the specified tolerance in X
Definition: exception.hpp:501
@ GSL_ERANGE
output range error, e.g.
Definition: exception.hpp:473
@ GSL_ETOLG
cannot reach the specified tolerance in gradient
Definition: exception.hpp:502
@ GSL_EBADTOL
user specified an invalid tolerance
Definition: exception.hpp:484
@ GSL_ETOL
failed to reach the specified tolerance
Definition: exception.hpp:485
@ GSL_EUNIMPL
requested feature not (yet) implemented
Definition: exception.hpp:495
@ GSL_EUNSUP
requested feature is not supported by the hardware
Definition: exception.hpp:494
@ GSL_ERUNAWAY
iterative process is out of control
Definition: exception.hpp:481
@ GSL_ENOMEM
malloc failed
Definition: exception.hpp:479
@ GSL_EBADLEN
matrix, vector lengths are not conformant
Definition: exception.hpp:490
@ GSL_EFAULT
invalid pointer
Definition: exception.hpp:474
@ GSL_EROUND
failed because of roundoff error
Definition: exception.hpp:489
@ GSL_ESING
apparent singularity detected
Definition: exception.hpp:492
@ GSL_EBADFUNC
problem with user-supplied function
Definition: exception.hpp:480
@ GSL_EUNDRFLW
underflow
Definition: exception.hpp:486
static void(*)(char const *, char const *, int, int) set_handler_gsl_exceptions()
Set the handler function to handle exceptions.
Definition: exception.hpp:457
int get_line() const
Get the line number at which a GSL error handler caused the exception.
Definition: exception.hpp:426
static void handler_gsl_exceptions(char const *reason, char const *file, int line, int gsl_errno)
The default exception handler for gsl.
Definition: exception.hpp:514
int get_gsl_errno() const
Get an error number.
Definition: exception.hpp:432
char const * strerror() const
Get a standard GSL message corresponding to the error number.
Definition: exception.hpp:437
static void enable()
Set the handler function to handle exceptions.
Definition: exception.hpp:452
char const * file
The file that cause this exception.
Definition: exception.hpp:528
int const line
The line number in file at which exception handler was called.
Definition: exception.hpp:532
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 ...
Definition: exception.hpp:398
char const * get_reason() const
Get the message explaining the reason for the error/exception.
Definition: exception.hpp:416
The gsl package creates an interface to the GNU Scientific Library for C++.
Definition: blas.hpp:34