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  * Copyright (C) 2003 by the Board of Trustees of Leland Stanford
00011  * Junior University and by New York University. 
00012  *
00013  * License to use, copy, modify, sell and/or distribute this software
00014  * and its documentation for any purpose is hereby granted without
00015  * royalty, subject to the terms and conditions defined in the \ref
00016  * LICENSE file provided with this distribution.  In particular:
00017  *
00018  * - The above copyright notice and this permission notice must appear
00019  * in all copies of the software and related documentation.
00020  *
00021  * - THE SOFTWARE IS PROVIDED "AS-IS", WITHOUT ANY WARRANTIES,
00022  * EXPRESSED OR IMPLIED.  USE IT AT YOUR OWN RISK.
00023  * 
00024  * <hr>
00025  * 
00026  * A generic exception.  Any thrown exception must inherit from this
00027  * class and whenever possible, set the error message.
00028  */
00029 /*****************************************************************************/
00030 
00031 #ifndef _CVC_lite__exception_h_
00032 #define _CVC_lite__exception_h_
00033 
00034 #include <string>
00035 #include <iostream>
00036 
00037 namespace CVCL {
00038 
00039   class Exception {
00040   protected:
00041     std::string d_msg;
00042   public:
00043     // Constructors
00044     Exception(): d_msg("Unknown exception") { }
00045     Exception(const std::string& msg): d_msg(msg) { }
00046     Exception(char* msg): d_msg(msg) { }
00047     // Destructor
00048     virtual ~Exception() { }
00049     // NON-VIRTUAL METHODs for setting and printing the error message
00050     void setMessage(const std::string& msg) { d_msg = msg; }
00051     // Printing: feel free to redefine toString().  When inherited,
00052     // it's recommended that this method print the type of exception
00053     // before the actual message.
00054     virtual std::string toString() const { return d_msg; }
00055     // No need to overload operator<< for the inherited classes
00056     friend std::ostream& operator<<(std::ostream& os, const Exception& e);
00057 
00058   }; // end of class Exception
00059 
00060   inline std::ostream& operator<<(std::ostream& os, const Exception& e) {
00061     return os << e.toString();
00062   }
00063 
00064 } // end of namespace CVCL 
00065 
00066 #endif

Generated on Thu Apr 13 16:57:31 2006 for CVC Lite by  doxygen 1.4.4