Object-oriented Scientific Computing Library: Version 0.910
exception.h
Go to the documentation of this file.
00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006-2012, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   O2scl is free software; you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation; either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   O2scl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00020 
00021   -------------------------------------------------------------------
00022 */
00023 #ifndef O2SCL_EXCEPTION_H
00024 #define O2SCL_EXCEPTION_H
00025 
00026 /** \file exception.h
00027     \brief File for definitions for err_hnd_cpp and the exceptions
00028 
00029     See also \ref err_hnd.h .
00030 */
00031 
00032 #include <stdexcept>
00033 #include <iostream>
00034 
00035 #include <o2scl/err_hnd.h>
00036 
00037 #ifndef DOXYGENP
00038 namespace o2scl {
00039 #endif
00040   
00041   /** \brief Generic exception
00042 
00043       This class derives from <tt>std::exception</tt>.
00044 
00045       The errors which are handled with this exception type are
00046       - gsl_failure (-1) Failure \n
00047       - gsl_efailed (5) Generic failure \n
00048       - gsl_esanity (7) Sanity check failed \n
00049       - gsl_eunsup (23) Requested feature is not 
00050       supported by the hardware \n
00051       - gsl_eunimpl (24) Requested feature not 
00052       (yet) implemented  
00053     
00054   */
00055   class exc_exception : public std::exception {
00056 
00057   public:
00058     
00059     /// Create an exception 
00060   exc_exception() : std::exception() {
00061     }
00062 
00063     virtual ~exc_exception() throw() {}
00064 
00065     /// Return the error string
00066     virtual const char* what() const throw()
00067     {
00068       return err_hnd->get_str();
00069     }
00070   
00071   };
00072 
00073   /** \brief Logic error exception
00074 
00075       This class derives from <tt>std::logic_error</tt>.
00076 
00077       The error which is handled with this exception type is
00078       - gsl_ememtype (34) Incorrect type for memory object
00079 
00080   */
00081   class exc_logic_error : public std::logic_error {
00082     
00083   public:
00084     
00085     /// Create an exception with description provided in \c s
00086   exc_logic_error(const std::string &s) : std::logic_error(s) {
00087     }
00088     
00089     virtual ~exc_logic_error() throw() {}
00090     
00091     /// Return the error string
00092     virtual const char* what() const throw()
00093     {
00094       return err_hnd->get_str();
00095     }
00096   
00097   };
00098 
00099   /** \brief Invalid argument exception
00100 
00101       This class derives from <tt>std::invalid_argument</tt>.
00102 
00103       The errors which are handled with this exception type are
00104       - gsl_einval (4) invalid argument supplied by user \n
00105       - gsl_ebadtol (13) user specified an invalid tolerance \n
00106       - gsl_ebadlen (19) matrix, vector lengths are not conformant \n
00107       - gsl_enotsqr (20) matrix not square \n
00108       - gsl_eindex (36) Invalid index for array or matrix 
00109   */
00110   class exc_invalid_argument : public std::invalid_argument {
00111     
00112   public:
00113     
00114     /// Create an exception with description provided in \c s
00115   exc_invalid_argument(const std::string &s) : std::invalid_argument(s) {
00116     }
00117     
00118     virtual ~exc_invalid_argument() throw() {}
00119     
00120     /// Return the error string
00121     virtual const char* what() const throw()
00122     {
00123       return err_hnd->get_str();
00124     }
00125   
00126   };
00127 
00128   /** \brief Generic runtime error exception
00129 
00130       This class derives from <tt>std::runtime_error</tt>.
00131 
00132       The errors which are handled with this exception type are
00133       - gsl_efault (3) invalid pointer \n
00134       - gsl_efactor (6) factorization failed \n
00135       - gsl_enomem (8) malloc failed \n
00136       - gsl_ebadfunc (9) problem with user-supplied function \n
00137       - gsl_erunaway (10) iterative process is out of control \n
00138       - gsl_emaxiter (11) exceeded max number of iterations \n
00139       - gsl_etol (14) failed to reach the specified tolerance \n
00140       - gsl_eloss (17) loss of accuracy \n
00141       - gsl_eround (18) failed because of roundoff error \n
00142       - gsl_esing (21) apparent singularity detected \n
00143       - gsl_ediverge (22) integral or series is divergent \n
00144       - gsl_ecache (25) cache limit exceeded \n
00145       - gsl_etable (26) table limit exceeded \n
00146       - gsl_enoprog (27) iteration is not making progress toward solution \n
00147       - gsl_enoprogj (28) jacobian evaluations are not
00148       improving the solution \n
00149       - gsl_etolf (29) cannot reach the specified tolerance in f \n
00150       - gsl_etolx (30) cannot reach the specified tolerance in x \n
00151       - gsl_etolg (31) cannot reach the specified tolerance in gradient \n
00152       - gsl_enotfound (33) Generic "not found" result \n
00153       - gsl_outsidecons (37) Outside constraint region
00154 
00155   */
00156   class exc_runtime_error : public std::runtime_error {
00157 
00158   public:
00159     
00160   exc_runtime_error(const std::string &s) : std::runtime_error(s) {
00161     }
00162     
00163     /// Create an exception with description provided in \c s
00164     virtual ~exc_runtime_error() throw() {}
00165     
00166     /// Return the error string
00167     virtual const char* what() const throw()
00168     {
00169       return err_hnd->get_str();
00170     }
00171   
00172   };
00173   
00174   /** \brief Range error runtime exception
00175 
00176       This class derives from <tt>std::range_error</tt>.
00177 
00178       The errors which are handled with this exception type are
00179       - gsl_edom (1) input domain error, e.g sqrt(-1) \n
00180       - gsl_erange (2) output range error, e.g. exp(1e100) \n
00181       - gsl_eundrflw (15) underflow   
00182   */
00183   class exc_range_error : public std::range_error {
00184 
00185   public:
00186     
00187     /// Create an exception with description provided in \c s
00188   exc_range_error(const std::string &s) : std::range_error(s) {
00189     }
00190     
00191     virtual ~exc_range_error() throw() {}
00192     
00193     /// Return the error string
00194     virtual const char* what() const throw()
00195     {
00196       return err_hnd->get_str();
00197     }
00198   
00199   };
00200   
00201   /** \brief Overflow error runtime exception
00202 
00203       This class derives from <tt>std::overflow_error</tt>.
00204 
00205       The errors which are handled with this exception type are
00206       - gsl_ezerodiv (12) tried to divide by zero \n
00207       - gsl_eovrflw (16) overflow 
00208   */
00209   class exc_overflow_error : public std::overflow_error {
00210 
00211   public:
00212     
00213     /// Create an exception with description provided in \c s
00214   exc_overflow_error(const std::string &s) : std::overflow_error(s) {
00215     }
00216     
00217     virtual ~exc_overflow_error() throw() {}
00218     
00219     /// Return the error string
00220     virtual const char* what() const throw()
00221     {
00222       return err_hnd->get_str();
00223     }
00224   
00225   };
00226   
00227   /** \brief I/O failure error exception
00228 
00229       This class derives from <tt>std::ios::failure</tt>.
00230 
00231       The errors which are handled with this exception type are
00232       - gsl_eof=32 end of file \n
00233       - gsl_efilenotfound=35 File not found
00234   */
00235   class exc_ios_failure : public std::ios::failure {
00236     
00237   public:
00238 
00239     /// Create an exception with description provided in \c s
00240   exc_ios_failure(const std::string &s) : std::ios::failure(s) {
00241     }
00242     
00243     virtual ~exc_ios_failure() throw() {}
00244     
00245     /// Return the error string
00246     virtual const char* what() const throw()
00247     {
00248       return err_hnd->get_str();
00249     }
00250   
00251   };
00252   
00253   /** \brief Error handler to throw C++ exceptions
00254 
00255       The default error handler, \ref def_err_hnd, is of this type.
00256    */
00257   class err_hnd_cpp : public err_hnd_gsl {
00258     
00259   public:  
00260 
00261     err_hnd_cpp();
00262 
00263     virtual ~err_hnd_cpp() throw() {}
00264     
00265     /// Set an error 
00266     virtual void set(const char *reason, const char *file, 
00267                      int line, int lerrno);
00268 
00269     /// Return type ("err_hnd_cpp")
00270     virtual const char *type() const { return "err_hnd_cpp"; }
00271 
00272   };
00273 
00274   /** \brief The default error handler
00275    */      
00276   extern err_hnd_cpp def_err_hnd;
00277 
00278 #ifndef DOXYGENP
00279 }
00280 #endif
00281 
00282 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.