| VRS - The Virtual Rendering System |
| version 3.3 |
00001 /****************************************************************************** 00002 * VRS - The Virtual Rendering System 00003 * Copyright (C) 2000-2004 Computer Graphics Systems Group at the 00004 * Hasso-Plattner-Institute (HPI), Potsdam, Germany. 00005 * 00006 * This library is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or (at 00009 * your option) any later version. This library is distributed in the hope 00010 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 00011 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU Lesser General Public License for more details. You should have received 00013 * a copy of the GNU Lesser+ General Public License along with this library; if 00014 * not, write to the FreeSoftware Foundation, Inc., 59 Temple Place, Suite 330, 00015 * Boston, MA, 02111-1307, USA. 00016 ******************************************************************************/ 00017 00018 // $Id: exception.h 4633 2005-01-03 01:43:11Z klimetschek $ 00019 // $Date: 2005-01-03 02:43:11 +0100 (Mon, 03 Jan 2005) $ 00020 // $Revision: 4633 $ 00021 // $State$ 00022 // $Author: klimetschek $ 00023 // 00024 // $Log$ 00025 // Revision 1.14 2005/01/03 01:43:07 klimetschek 00026 // - modified win32 project layout, splitted vrs.vcproj into vrs_container, vrs_core, vrs_sg, vrs_image, vrs_opengl and vrs_io 00027 // - removed vrs.vcproj 00028 // minor things: 00029 // - added all glutexamples to vrs4glut.sln 00030 // - fixed some problems in glutexamples 00031 // - removed all project references from all VS projects (using solution wide project dependencies instead) 00032 // 00033 // Revision 1.13 2004/11/05 13:58:09 basch 00034 // Class comment changed (Doxygen style) 00035 // 00036 // Revision 1.12 2004/06/15 09:37:21 baumann 00037 // missing dtor (with throw()) added 00038 // 00039 // Revision 1.11 2004/06/15 05:35:22 baumann 00040 // VRS::Exception rewritten 00041 // 00042 // Revision 1.10 2004/03/12 16:28:38 baumann 00043 // macros VRS_NAMESPACE_BEGIN/_END expanded and removed 00044 // 00045 // Revision 1.9 2003/12/07 11:12:59 kirsch 00046 // added qualified namespace of std::string 00047 // 00048 // Revision 1.8 2003/11/07 14:19:24 kirsch 00049 // removed leading underscore from include guards 00050 // 00051 // Revision 1.7 2003/03/18 23:05:07 skirsch 00052 // improvements on the comments 00053 // 00054 // Revision 1.6 2002/06/11 13:18:28 kirsch 00055 // cleaned up includes of engine 00056 // 00057 // Revision 1.5 2002/02/19 10:34:07 kosta 00058 // undone all changes since 2002-02-15 00059 // 00060 // Revision 1.3 2002/01/15 16:25:53 kosta 00061 // macros rewritten for a better namespace support 00062 // 00063 // Revision 1.2 2001/11/13 16:36:30 kirsch 00064 // changed line feed to unix style (removed control-M) 00065 // 00066 // Revision 1.1.1.1 2001/06/08 08:09:20 kirsch 00067 // imported alpha-version by olli 00068 // 00069 00070 #ifndef VRS_EXCEPTION_H 00071 #define VRS_EXCEPTION_H 00072 00073 #include <vrs/config.h> 00074 #include <sstream> // for std::ostringstream 00075 #include <stdexcept> // for std::exception 00076 00077 namespace VRS { 00078 00080 class VRS_CORE_API Exception : 00081 public std::exception 00082 { 00083 00084 public: 00085 Exception( 00086 const std::string& message, 00087 const std::string& sourceFileName, 00088 unsigned int sourceFileLine, 00089 const std::string& condition 00090 ) throw(); 00092 00093 virtual ~Exception() throw() { } 00094 00095 const std::string& message() const throw(); 00097 const std::string& sourceFileName() const throw(); 00099 unsigned int sourceFileLine() const throw(); 00101 const std::string& condition() const throw(); 00103 00104 public: 00105 virtual const char* what() const throw(); 00109 private: 00110 const std::string m_message; 00111 const std::string m_sourceFileName; 00112 const unsigned int m_sourceFileLine; 00113 const std::string m_condition; 00114 }; // class Exception 00115 00116 // This macro can be used to define new exceptions based on existing ones, e.g.: 00117 // VRS_DEFINE_EXCEPTION(IOException, Exception); 00118 // This definition can be done inside and outside of class declarations. 00119 00120 #define VRS_DEFINE_EXCEPTION(NEW_EXCEPTION, BASE_EXCEPTION) \ 00121 class NEW_EXCEPTION : \ 00122 public BASE_EXCEPTION \ 00123 { \ 00124 public: \ 00125 NEW_EXCEPTION( \ 00126 const std::string& message, \ 00127 const std::string& sourceFileName, \ 00128 unsigned int sourceFileLine, \ 00129 const std::string& condition \ 00130 ) throw() : \ 00131 BASE_EXCEPTION(message, sourceFileName, sourceFileLine, condition) \ 00132 { } \ 00133 }; // class NEW_EXCEPTION 00134 00135 // This macro can be used to throw the given exception (VRS:Exception or derived 00136 // from it) if the given condition is true; the message can be formated using 00137 // the C++ ostream operators; e.g.: 00138 // VRS_THROW_IF(!file.good(), IOException, "could not read from file: " << filename); 00139 00140 #define VRS_THROW_IF(CONDITION, EXCEPTION, MESSAGE) \ 00141 if(CONDITION) { \ 00142 std::ostringstream out; \ 00143 out.precision(15); \ 00144 out << MESSAGE; \ 00145 throw EXCEPTION(out.str(), __FILE__, __LINE__, #CONDITION); \ 00146 } 00147 00148 // This macro can be used to throw the given exception (VRS:Exception or derived 00149 // from it); the message can be formated using the C++ ostream operators; e.g.: 00150 // VRS_THROW(IOException, "could not read from file: " << filename); 00151 00152 #define VRS_THROW(EXCEPTION, MESSAGE) \ 00153 VRS_THROW_IF(true, EXCEPTION, MESSAGE) 00154 00155 00156 // Defines the "out-of-memory-exception". 00157 VRS_DEFINE_EXCEPTION(OutOfMemoryException, Exception); 00158 00159 } // namespace VRS 00160 00161 #endif // VRS_EXCEPTION_H