Ipopt  3.12.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IpException.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2006 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id: IpException.hpp 2023 2011-06-18 18:49:49Z stefan $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8 
9 #ifndef __IPEXCEPTION_HPP__
10 #define __IPEXCEPTION_HPP__
11 
12 #include "IpUtils.hpp"
13 #include "IpJournalist.hpp"
14 
15 /* This file contains a base class for all exceptions
16  * and a set of macros to help with exceptions
17  */
18 
19 namespace Ipopt
20 {
21 
58  {
59  public:
63  IpoptException(std::string msg, std::string file_name, Index line_number, std::string type="IpoptException")
64  :
65  msg_(msg),
66  file_name_(file_name),
67  line_number_(line_number),
68  type_(type)
69  {}
70 
73  :
74  msg_(copy.msg_),
75  file_name_(copy.file_name_),
77  type_(copy.type_)
78  {}
79 
81  virtual ~IpoptException()
82  {}
84 
86  void ReportException(const Journalist& jnlst,
87  EJournalLevel level = J_ERROR) const
88  {
89  jnlst.Printf(level, J_MAIN,
90  "Exception of type: %s in file \"%s\" at line %d:\n Exception message: %s\n",
91  type_.c_str(), file_name_.c_str(), line_number_, msg_.c_str());
92  }
93 
94  const std::string& Message() const
95  {
96  return msg_;
97  }
98 
99  private:
109  IpoptException();
110 
112  void operator=(const IpoptException&);
114 
115  std::string msg_;
116  std::string file_name_;
118  std::string type_;
119  };
120 
121 } // namespace Ipopt
122 
123 #define THROW_EXCEPTION(__except_type, __msg) \
124  throw __except_type( (__msg), (__FILE__), (__LINE__) );
125 
126 #define ASSERT_EXCEPTION(__condition, __except_type, __msg) \
127  if (! (__condition) ) { \
128  std::string newmsg = #__condition; \
129  newmsg += " evaluated false: "; \
130  newmsg += __msg; \
131  throw __except_type( (newmsg), (__FILE__), (__LINE__) ); \
132  }
133 
134 #define DECLARE_STD_EXCEPTION(__except_type) \
135  class __except_type : public Ipopt::IpoptException \
136  { \
137  public: \
138  __except_type(std::string msg, std::string fname, Ipopt::Index line) \
139  : Ipopt::IpoptException(msg,fname,line, #__except_type) {} \
140  __except_type(const __except_type& copy) \
141  : Ipopt::IpoptException(copy) {} \
142  private: \
143  __except_type(); \
144  void operator=(const __except_type&); \
145  }
146 
147 #endif
const std::string & Message() const
Definition: IpException.hpp:94
This is the base class for all exceptions.
Definition: IpException.hpp:57
EJournalLevel
Print Level Enum.
IpoptException()
Default Constructor.
IpoptException(std::string msg, std::string file_name, Index line_number, std::string type="IpoptException")
Constructor.
Definition: IpException.hpp:63
void ReportException(const Journalist &jnlst, EJournalLevel level=J_ERROR) const
Method to report the exception to a journalist.
Definition: IpException.hpp:86
virtual void Printf(EJournalLevel level, EJournalCategory category, const char *format,...) const
Method to print a formatted string.
void operator=(const IpoptException &)
Overloaded Equals Operator.
int Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:19
IpoptException(const IpoptException &copy)
Copy Constructor.
Definition: IpException.hpp:72
Class responsible for all message output.
char * file_name
virtual ~IpoptException()
Default destructor.
Definition: IpException.hpp:81