SundanceExceptions.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_EXCEPTIONS_H
00032 #define SUNDANCE_EXCEPTIONS_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "Teuchos_ConfigDefs.hpp"
00036 #include "Teuchos_TestForException.hpp"
00037 #include <stdexcept>
00038 
00039 #ifndef DOXYGEN_DEVELOPER_ONLY
00040 
00041 //bvbw for backard compatibility reasons
00042 //     I could not get this to work with ifdefs hence the hack
00043 
00044 #define SUNDANCE_ERROR7(msg) \
00045 { \
00046   TestForException_break(); \
00047   TeuchosOStringStream omsg; \
00048   omsg << __FILE__ << ":" << __LINE__ << ": " \
00049        << ": " << msg; \
00050   throw Sundance::RuntimeError(TEUCHOS_OSTRINGSTREAM_GET_C_STR(omsg)); \
00051 }
00052 
00053 #define SUNDANCE_ERROR(msg) \
00054 { \
00055   TeuchosOStringStream omsg; \
00056   omsg << __FILE__ << ":" << __LINE__ << ": " \
00057        << ": " << msg; \
00058   const std::string &omsgstr = omsg.str(); \
00059   TestForException_break(omsgstr); \
00060   throw Sundance::RuntimeError(TEUCHOS_OSTRINGSTREAM_GET_C_STR(omsg)); \
00061 }
00062 
00063 
00064 #define SUNDANCE_TRACE(e) \
00065 { \
00066   TeuchosOStringStream omsg; \
00067   omsg << e.what() << std::endl \
00068   << "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
00069   throw Sundance::RuntimeError(TEUCHOS_OSTRINGSTREAM_GET_C_STR(omsg)); \
00070 }
00071 
00072 #define SUNDANCE_TRACE_MSG(e, msg)                      \
00073 { \
00074   TeuchosOStringStream omsg; \
00075   omsg << e.what() << std::endl \
00076   << "caught in " << __FILE__ << ":" << __LINE__ << std::endl ; \
00077   omsg << msg << std::endl; \
00078   throw Sundance::RuntimeError(TEUCHOS_OSTRINGSTREAM_GET_C_STR(omsg)); \
00079 }
00080 
00081 #define SUNDANCE_BOUNDSCHECK(i, low, high, msg) \
00082 { \
00083   TEST_FOR_EXCEPTION( i < low || i > high, Sundance::RuntimeError, \
00084                      "Bounds violation: " << #i << "is out of range [" \
00085                       << #low << ", " << #high << "]") \
00086 }
00087 
00088 #define SUNDANCE_CHECK_ARRAY_SIZE_MATCH(a1, a2) \
00089   {\
00090     TEST_FOR_EXCEPTION(a1.size() != a2.size(), Sundance::RuntimeError, \
00091       "Mismatched array sizes: size(" << #a1 << ")=" << a1.size() \
00092       << " size(" << #a2 << ")=" << a2.size() << ". Expected equal sizes");\
00093   }
00094 
00095 
00096 
00097 namespace Sundance
00098 {
00099   /**
00100    * InternalError is thrown when an "impossible" case is detected
00101    * in Sundance's internals. Occurance of an InternalError indicates
00102    * either a bug in Sundance or runtime memory corruption that is
00103    * scrambling an object's virtual tables.
00104    */
00105   class InternalError : public std::logic_error
00106     {
00107     public:
00108       /** */
00109       InternalError(const std::string& msg);
00110     };
00111 
00112   /**
00113    * RuntimeError is an exception that occurs as a result of invalid
00114    * user-level code.
00115    */
00116   class RuntimeError : public std::runtime_error
00117     {
00118     public:
00119       /** */
00120       RuntimeError(const std::string& msg);
00121     };
00122 
00123   /**
00124    * BadSymbolicsError is thrown when a mathematically nonsensical
00125    * expression is detected. Unfortunately, it is possible to form expressions
00126    * that are legal C++ but illegal mathematics. For example, one can
00127    * happily divide a differential operator by another expression,
00128    * \code
00129    * Expr f = new UnknownFunction();
00130    * Expr dx = new Derivative(0);
00131    * Expr e = dx/f;
00132    * \endcode
00133    */
00134   class BadSymbolicsError : public RuntimeError
00135     {
00136     public:
00137       /** */
00138       BadSymbolicsError(const std::string& msg);
00139     };
00140 }
00141 
00142                   
00143 #endif  /* DOXYGEN_DEVELOPER_ONLY */  
00144 
00145 
00146 #endif

Site Contact