/home/coin/SVN-release/CoinAll-1.1.0/Ipopt/src/Common/IpException.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2006 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: IpException.hpp 1019 2007-06-24 03:52:34Z andreasw $
00006 //
00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2004-08-13
00008 
00009 #ifndef __IPEXCEPTION_HPP__
00010 #define __IPEXCEPTION_HPP__
00011 
00012 #include "IpUtils.hpp"
00013 #include "IpJournalist.hpp"
00014 
00015 /*  This file contains a base class for all exceptions
00016  *  and a set of macros to help with exceptions
00017  */
00018 
00019 namespace Ipopt
00020 {
00021 
00057   class IpoptException
00058   {
00059   public:
00063     IpoptException(std::string msg, std::string file_name, Index line_number, std::string type="IpoptException")
00064         :
00065         msg_(msg),
00066         file_name_(file_name),
00067         line_number_(line_number),
00068         type_(type)
00069     {}
00070 
00072     IpoptException(const IpoptException& copy)
00073         :
00074         msg_(copy.msg_),
00075         file_name_(copy.file_name_),
00076         line_number_(copy.line_number_),
00077         type_(copy.type_)
00078     {}
00079 
00081     virtual ~IpoptException()
00082     {}
00084 
00086     void ReportException(const Journalist& jnlst,
00087                          EJournalLevel level = J_ERROR) const
00088     {
00089       jnlst.Printf(level, J_MAIN,
00090                    "Exception of type: %s in file \"%s\" at line %d:\n Exception message: %s\n",
00091                    type_.c_str(), file_name_.c_str(),  line_number_, msg_.c_str());
00092     }
00093 
00094     const std::string& Message() const
00095     {
00096       return msg_;
00097     }
00098 
00099   private:
00109     IpoptException();
00110 
00112     void operator=(const IpoptException&);
00114 
00115     std::string msg_;
00116     std::string file_name_;
00117     Index line_number_;
00118     std::string type_;
00119   };
00120 
00121 #define THROW_EXCEPTION(__except_type, __msg) \
00122   throw __except_type( (__msg), (__FILE__), (__LINE__) );
00123 
00124 #define ASSERT_EXCEPTION(__condition, __except_type, __msg) \
00125   if (! (__condition) ) { \
00126     std::string newmsg = #__condition; \
00127     newmsg += " evaluated false: "; \
00128     newmsg += __msg; \
00129     throw __except_type( (newmsg), (__FILE__), (__LINE__) ); \
00130   }
00131 
00132 #define DECLARE_STD_EXCEPTION(__except_type) \
00133     class __except_type : public IpoptException \
00134     { \
00135     public: \
00136       __except_type(std::string msg, std::string fname, Index line) \
00137  : IpoptException(msg,fname,line, #__except_type) {} \
00138       __except_type(const __except_type& copy) \
00139  : IpoptException(copy) {} \
00140     private: \
00141        __except_type(); \
00142        void operator=(const __except_type&); \
00143     }
00144 
00145 } // namespace Ipopt
00146 
00147 #endif

Generated on Sun Nov 14 14:06:35 2010 for Coin-All by  doxygen 1.4.7