Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Exception.hh

Go to the documentation of this file.
00001 /*
00002 
00003     Exception class
00004     Copyright (C) 2001 Jussi Laako
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 */
00021 
00022 
00023 #include <exception>
00024 #include <string>
00025 #include <cstring>
00026 #include <cstdio>
00027 
00028 
00029 #ifndef EXCEPTION_HH
00030     #define EXCEPTION_HH
00031 
00032 
00033     class clException : public std::exception
00034     {
00035             int iCode;
00036             std::string strMsg;
00037         public:
00038             clException () throw()
00039                 { }
00040             clException (int iErrorCode) throw()
00041                 {
00042                     char cpConvBuf[79];  /* Enough for 256-bit integers */
00043                     iCode = iErrorCode;
00044                     sprintf(cpConvBuf, "%i", iErrorCode);
00045                     strMsg = std::string(cpConvBuf);
00046                 }
00047             clException (const std::string &strErrorMsg) throw()
00048                 {
00049                     iCode = 0;
00050                     strMsg = strErrorMsg;
00051                 }
00052             clException (const std::string &strErrorMsg, int iErrorCode)
00053                 throw()
00054                 {
00055                     iCode = iErrorCode;
00056                     strMsg = strErrorMsg;
00057                 }
00058             clException (const char *cpErrorMsg) throw()
00059                 {
00060                     iCode = 0;
00061                     strMsg = std::string(cpErrorMsg);
00062                 }
00063             clException (const char *cpErrorMsg, int iErrorCode) throw()
00064                 {
00065                     iCode = iErrorCode;
00066                     strMsg = std::string(cpErrorMsg);
00067                 }
00068             virtual ~clException () throw()
00069                 { }
00070             operator int () const throw()
00071                 {
00072                     return iCode;
00073                 }
00074             operator std::string () const throw()
00075                 {
00076                     return strMsg;
00077                 }
00078             virtual const char * what () const throw()
00079                 {
00080                     return strMsg.c_str();
00081                 }
00082     };
00083 
00084 
00085 #endif

Generated on Tue Mar 2 19:46:44 2004 for libDSP by doxygen 1.3.6