exception.h

Go to the documentation of this file.
00001 /*****************************************************************************/
00002 /*!
00003  * \file exception.h
00004  * 
00005  * Author: Sergey Berezin
00006  * 
00007  * Created: Thu Feb  6 13:09:44 2003
00008  *
00009  * <hr>
00010  *
00011  * License to use, copy, modify, sell and/or distribute this software
00012  * and its documentation for any purpose is hereby granted without
00013  * royalty, subject to the terms and conditions defined in the \ref
00014  * LICENSE file provided with this distribution.
00015  * 
00016  * <hr>
00017  * 
00018  * A generic exception.  Any thrown exception must inherit from this
00019  * class and whenever possible, set the error message.
00020  */
00021 /*****************************************************************************/
00022 
00023 #ifndef _cvc3__exception_h_
00024 #define _cvc3__exception_h_
00025 
00026 #include <string>
00027 #include <iostream>
00028 
00029 namespace CVC3 {
00030 
00031   class Exception {
00032   protected:
00033     std::string d_msg;
00034   public:
00035     // Constructors
00036     Exception(): d_msg("Unknown exception") { }
00037     Exception(const std::string& msg): d_msg(msg) { }
00038     Exception(char* msg): d_msg(msg) { }
00039     // Destructor
00040     virtual ~Exception() { }
00041     // NON-VIRTUAL METHODs for setting and printing the error message
00042     void setMessage(const std::string& msg) { d_msg = msg; }
00043     // Printing: feel free to redefine toString().  When inherited,
00044     // it's recommended that this method print the type of exception
00045     // before the actual message.
00046     virtual std::string toString() const { return d_msg; }
00047     // No need to overload operator<< for the inherited classes
00048     friend std::ostream& operator<<(std::ostream& os, const Exception& e);
00049 
00050   }; // end of class Exception
00051 
00052   inline std::ostream& operator<<(std::ostream& os, const Exception& e) {
00053     return os << e.toString();
00054   }
00055 
00056 } // end of namespace CVC3 
00057 
00058 #endif

Generated on Tue Jul 3 14:33:36 2007 for CVC3 by  doxygen 1.5.1