- Main Page
- Classes
- Files

- File List
- File Members

# 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 Eclipse Public License.
    00004 //
    00005 // $Id: IpException.hpp 2023 2011-06-18 18:49:49Z stefan $
    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 } // namespace Ipopt
    00122
    00123 #define THROW_EXCEPTION(__except_type, __msg) \
    00124   throw __except_type( (__msg), (__FILE__), (__LINE__) );
    00125
    00126 #define ASSERT_EXCEPTION(__condition, __except_type, __msg) \
    00127   if (! (__condition) ) { \
    00128     std::string newmsg = #__condition; \
    00129     newmsg += " evaluated false: "; \
    00130     newmsg += __msg; \
    00131     throw __except_type( (newmsg), (__FILE__), (__LINE__) ); \
    00132   }
    00133
    00134 #define DECLARE_STD_EXCEPTION(__except_type) \
    00135     class __except_type : public Ipopt::IpoptException \
    00136     { \
    00137     public: \
    00138       __except_type(std::string msg, std::string fname, Ipopt::Index line) \
    00139  : Ipopt::IpoptException(msg,fname,line, #__except_type) {} \
    00140       __except_type(const __except_type& copy) \
    00141  : Ipopt::IpoptException(copy) {} \
    00142     private: \
    00143        __except_type(); \
    00144        void operator=(const __except_type&); \
    00145     }
    00146
    00147 #endif

All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines