C:/programs/SCPPNT/src/include/scppnt_error.h

00001 /*! \file sccpnt_error.h
00002  \brief Exception classes used to signal errors.
00003  
00004  Declarations of classes used in throwing
00005  exceptions indicating various types of run-time errors.
00006  */
00007 
00008 /*
00009 
00010  Simple C++ Numerical Toolkit (SCPPNT)
00011  http://www.smallwaters.com/software/cpp/scppnt.html
00012  This release updates original work contributed by 
00013  Brad Hanson (http://www.b-a-h.com/) in 2001.
00014 
00015  */
00016 
00017 #ifndef SCPPNTERROR
00018 #define SCPPNTERROR
00019 
00020 namespace SCPPNT
00021 {
00022 
00023   //! General exception class from which classes indicating more specific types are errors are derived.
00024   class Exception
00025   {
00026 
00027 public:
00028 
00029     //! Constructor
00030     Exception();
00031 
00032     //! Destructor
00033     virtual ~Exception();
00034 
00035     //! Returns message describing the error that occurred
00036     virtual const char *what() const
00037     {
00038       return message;
00039     }
00040 
00041 protected:
00042 
00043     //! concatenate string to end of message if there is sufficient space left
00044     void AppendToMessage(const char *s);
00045 
00046     //! return maximum number of characters in message
00047     int MaxChar()
00048     {
00049       return 200;
00050     }
00051 
00052     //! space to hold message
00053     char message[201];
00054 
00055   };
00056 
00057   //! Errors in program logic that should be caught during program debugging.
00058   class LogicError : public Exception
00059   {
00060 
00061 public:
00062 
00063     //! Constructor from error type, error message, and function name form which exception is thrown
00064     LogicError(const char *type, const char *message, const char *func);
00065 
00066     //! Destructor
00067     virtual ~LogicError();
00068 
00069   };
00070 
00071   //! A function argument is invalid
00072   class InvalidArgument : public LogicError
00073   {
00074 public:
00075 
00076     //! Constructor from error message and function name form which exception is thrown
00077     InvalidArgument(const char *message, const char *func);
00078 
00079   };
00080 
00081   //! General run-time errors. Classes for specific types of run-time errors are derived from this class.
00082   class RuntimeError : public Exception
00083   {
00084 public:
00085 
00086     //! Constructor from error message and function name form which exception is thrown
00087     RuntimeError(const char *message, const char *func);
00088 
00089     //! Destructor
00090     virtual ~RuntimeError();
00091   };
00092 
00093   //! Attempt to access element outside vector or matrix bounds
00094   class BoundsError : public RuntimeError
00095   {
00096 public:
00097 
00098     //! Constructor from function name from which exception is thrown
00099     BoundsError(const char *func);
00100 
00101   };
00102 
00103   //! Bad dimension of vector or matrix argument of function
00104   class BadDimension : public RuntimeError
00105   {
00106 public:
00107 
00108     //! Constructor from function name from which exception is thrown
00109     BadDimension(const char *func);
00110 
00111   };
00112 
00113 } // namespace SCPPNT
00114 
00115 #endif // SCPPNTERROR

Generated on Tue Dec 18 23:34:06 2007 for SCPPNT by  doxygen 1.5.4