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

Exception.h

00001 #ifndef INCLUDE_EXCEPTION_H
00002 #define INCLUDE_EXCEPTION_H
00003 /*
00004  * This is the Loris C++ Class Library, implementing analysis, 
00005  * manipulation, and synthesis of digitized sounds using the Reassigned 
00006  * Bandwidth-Enhanced Additive Sound Model.
00007  *
00008  * Loris is Copyright (c) 1999-2004 by Kelly Fitz and Lippold Haken
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY, without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  *
00025  * Exception.h
00026  *
00027  * Definition of class Exception, a generic exception class, and 
00028  * commonly-used derived exception classes.
00029  *
00030  * Kelly Fitz, 17 Aug 1999
00031  * loris@cerlsoundgroup.org
00032  *
00033  * http://www.cerlsoundgroup.org/Loris/
00034  *
00035  */
00036 #include <stdexcept>
00037 #include <string>
00038 
00039 //  begin namespace
00040 namespace Loris {
00041 
00042 // ---------------------------------------------------------------------------
00043 //  class Exception
00044 //
00050 //
00051 class Exception : public std::exception
00052 {
00053 //  -- public interface --
00054 public:
00055 //  --- lifecycle ---
00056 
00066     Exception( const std::string & str, const std::string & where = "" );
00067      
00069     virtual ~Exception( void ) throw() 
00070     {
00071     }
00072 
00073 //  --- access/mutation ---
00074 
00079     const char * what( void ) const throw() { return _sbuf.c_str(); }
00080      
00086     Exception & append( const std::string & str );
00087      
00092     const std::string & str( void ) const 
00093     { 
00094        return _sbuf; 
00095     }
00096 
00097 //  -- instance variables --
00098 protected:
00099 
00101     std::string _sbuf;
00102     
00103 };  //  end of class Exception
00104 
00105 // ---------------------------------------------------------------------------
00106 //  class AssertionFailure
00107 //
00111 // 
00112 class AssertionFailure : public Exception
00113 {
00114 public: 
00115 
00125     AssertionFailure( const std::string & str, const std::string & where = "" ) : 
00126         Exception( std::string("Assertion failed -- ").append( str ), where ) 
00127     {
00128     }
00129     
00130 };  //  end of class AssertionFailure
00131 
00132 // ---------------------------------------------------------------------------
00133 //  class IndexOutOfBounds
00134 //
00137 //
00138 class IndexOutOfBounds : public Exception
00139 {
00140 public: 
00141 
00151     IndexOutOfBounds( const std::string & str, const std::string & where = "" ) : 
00152         Exception( std::string("Index out of bounds -- ").append( str ), where ) {}
00153         
00154 };  //  end of class IndexOutOfBounds
00155 
00156 
00157 // ---------------------------------------------------------------------------
00158 //  class InvalidObject
00159 //
00162 //
00163 class InvalidObject : public Exception
00164 {
00165 public: 
00166 
00176     InvalidObject( const std::string & str, const std::string & where = "" ) : 
00177         Exception( std::string("Invalid configuration or object -- ").append( str ), where ) 
00178     {
00179     }
00180     
00181 };  //  end of class InvalidObject
00182 
00183 // ---------------------------------------------------------------------------
00184 //  class InvalidIterator
00185 //
00188 //
00189 class InvalidIterator : public InvalidObject
00190 {
00191 public: 
00192 
00202     InvalidIterator( const std::string & str, const std::string & where = "" ) : 
00203         InvalidObject( std::string("Invalid Iterator -- ").append( str ), where ) 
00204     {
00205     }
00206     
00207 };  //  end of class InvalidIterator
00208 
00209 // ---------------------------------------------------------------------------
00210 //  class InvalidArgument
00211 //
00213 //
00214 class InvalidArgument : public Exception
00215 {
00216 public: 
00217 
00227     InvalidArgument( const std::string & str, const std::string & where = "" ) : 
00228         Exception( std::string("Invalid Argument -- ").append( str ), where ) 
00229     {
00230     }
00231     
00232 };  //  end of class InvalidArgument
00233 
00234 // ---------------------------------------------------------------------------
00235 //  class RuntimeError
00236 //
00239 //
00240 class RuntimeError : public Exception
00241 {
00242 public: 
00243 
00253     RuntimeError( const std::string & str, const std::string & where = "" ) : 
00254         Exception( std::string("Runtime Error -- ").append( str ), where ) 
00255     {
00256     }
00257     
00258 };  //  end of class RuntimeError
00259 
00260 // ---------------------------------------------------------------------------
00261 //  class FileIOException
00262 //
00264 //
00265 class FileIOException : public RuntimeError
00266 {
00267 public: 
00268 
00278     FileIOException( const std::string & str, const std::string & where = "" ) : 
00279         RuntimeError( std::string("File i/o error -- ").append( str ), where ) 
00280    {
00281    }
00282    
00283 };  //  end of class FileIOException
00284 
00285 // ---------------------------------------------------------------------------
00286 //  macros for throwing exceptions
00287 //
00288 //  The compelling reason for using macros instead of inlines for all these
00289 //  things is that the __FILE__ and __LINE__ macros will be useful.
00290 //
00291 #define __STR(x) __VAL(x)
00292 #define __VAL(x) #x
00293 #define Throw( exType, report )                                             \
00294     throw exType( report, " ( " __FILE__ " line: " __STR(__LINE__) " )" )
00295 
00296 #define Assert(test)                                                        \
00297     do {                                                                    \
00298         if (!(test)) Throw( Loris::AssertionFailure, #test );               \
00299     } while (false)
00300 
00301 
00302 }   //  end of namespace Loris
00303 
00304 #endif /* ndef INCLUDE_EXCEPTION_H */

Generated on Thu Apr 14 22:01:55 2005 for Loris by doxygen 1.3.4