Exception.hpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 
00030 #ifndef _EXCEPTION_HPP_
00031 #define _EXCEPTION_HPP_
00032 
00039 #include <string>
00040 
00041 #include <cfloat>
00042 #include <climits> //For UINT_MAX etc., necessary in gcc-4.3
00043 #include <cstdlib> //For system() etc., necessary in gcc-4.3
00044 
00046 const unsigned UNSIGNED_UNSET=UINT_MAX;
00048 const int INT_UNSET=INT_MAX;
00050 const double DOUBLE_UNSET=DBL_MAX;
00051 
00058 class Exception
00059 {
00060 private:
00061     std::string mMessage; 
00062     std::string mShortMessage; 
00064 public:
00072     Exception(const std::string& rMessage, const std::string& rFilename, unsigned lineNumber);
00073 
00079     std::string GetMessage() const;
00080 
00086     std::string GetShortMessage() const;
00087 
00097     std::string CheckShortMessage(std::string expected) const;
00098 
00108     std::string CheckShortMessageContains(std::string expected) const;
00109 };
00110 
00116 #define EXCEPTION(message) throw Exception(message, __FILE__, __LINE__)
00117 
00118 
00119 #include <boost/preprocessor/stringize.hpp>
00120 
00127 #define EXCEPT_IF_NOT(test) \
00128     if (!(test)) EXCEPTION("Assertion tripped: " BOOST_PP_STRINGIZE(test)) 
00129 
00135 #ifdef NDEBUG
00136 #define UNUSED_OPT(var) var=var
00137 #else
00138 #define UNUSED_OPT(var)
00139 #endif
00140 
00147 #define EXPECT0(cmd, arg) { \
00148     std::string _arg(arg); \
00149     int ret = cmd(_arg.c_str()); \
00150     if (ret != 0) { \
00151         EXCEPTION("Error executing command: " #cmd "(" + _arg + ")"); \
00152     } }
00153 
00160 #define MPIABORTIFNON0(cmd, arg) { \
00161     std::string _arg(arg); \
00162     int ret = cmd(_arg.c_str()); \
00163     if (ret != 0) { \
00164         std::cout << "Error executing command: " #cmd "(" + _arg + ")"; \
00165         MPI_Abort(PETSC_COMM_WORLD, -1); \
00166     } }
00167 
00174 #define EXPECTNON0(cmd, arg) { \
00175     std::string _arg = (arg); \
00176     int ret = cmd(_arg.c_str()); \
00177     if (ret == 0) { \
00178         EXCEPTION("Command: " #cmd "(" + _arg + ") succeeded and it shouldn't have"); \
00179     } }
00180 
00187 #define IGNORE_RET(cmd, arg) { \
00188     std::string _arg = (arg); \
00189     int ret = cmd(_arg.c_str()); \
00190     ret = ret; \
00191     }
00192 
00193 #endif // _EXCEPTION_HPP_

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5