Ipopt Documentation  
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 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
11 #ifndef __IPEXCEPTION_HPP__
12 #define __IPEXCEPTION_HPP__
13 
14 #include "IpUtils.hpp"
15 #include "IpJournalist.hpp"
16 
17 namespace Ipopt
18 {
19 
58 {
59 public:
62 
64  const std::string& msg,
65  const std::string& file_name,
66  Index line_number,
67  const std::string& type = "IpoptException"
68  )
69  : msg_(msg),
70  file_name_(file_name),
71  line_number_(line_number),
72  type_(type)
73  { }
74 
77  const IpoptException& copy
78  )
79  : msg_(copy.msg_),
80  file_name_(copy.file_name_),
81  line_number_(copy.line_number_),
82  type_(copy.type_)
83  { }
84 
86  virtual ~IpoptException()
87  { }
89 
92  const Journalist& jnlst,
93  EJournalLevel level = J_ERROR
94  ) const
95  {
96  jnlst.Printf(level, J_MAIN,
97  "Exception of type: %s in file \"%s\" at line %" IPOPT_INDEX_FORMAT ":\n Exception message: %s\n", type_.c_str(), file_name_.c_str(), line_number_, msg_.c_str());
98  }
99 
100  const std::string& Message() const
101  {
102  return msg_;
103  }
104 
105 private:
115 
117 
119  void operator=(
120  const IpoptException&
121  );
123 
124  std::string msg_;
125  std::string file_name_;
127  std::string type_;
128 };
129 
130 } // namespace Ipopt
131 
132 #define THROW_EXCEPTION(__except_type, __msg) \
133  throw __except_type( (__msg), (__FILE__), (__LINE__) );
134 
135 #define ASSERT_EXCEPTION(__condition, __except_type, __msg) \
136  if (! (__condition) ) { \
137  std::string newmsg = #__condition; \
138  newmsg += " evaluated false: "; \
139  newmsg += __msg; \
140  throw __except_type( (newmsg), (__FILE__), (__LINE__) ); \
141  }
142 
143 #define DECLARE_STD_EXCEPTION(__except_type) \
144  class IPOPTLIB_EXPORT __except_type : public Ipopt::IpoptException \
145  { \
146  public: \
147  __except_type(const std::string& msg, const std::string& fname, Ipopt::Index line) \
148  : Ipopt::IpoptException(msg,fname,line, #__except_type) {} \
149  __except_type(const __except_type& copy) \
150  : Ipopt::IpoptException(copy) {} \
151  private: \
152  __except_type(); \
153  void operator=(const __except_type&); \
154  }
155 
156 #endif
#define IPOPT_INDEX_FORMAT
Format specifier to use for ipindex in printf-format strings.
Definition: IpTypes.h:72
This is the base class for all exceptions.
Definition: IpException.hpp:58
IpoptException(const std::string &msg, const std::string &file_name, Index line_number, const std::string &type="IpoptException")
Constructor.
Definition: IpException.hpp:63
virtual ~IpoptException()
Default destructor.
Definition: IpException.hpp:86
const std::string & Message() const
void ReportException(const Journalist &jnlst, EJournalLevel level=J_ERROR) const
Method to report the exception to a journalist.
Definition: IpException.hpp:91
IpoptException(const IpoptException &copy)
Copy Constructor.
Definition: IpException.hpp:76
void operator=(const IpoptException &)
Default Assignment Operator.
IpoptException()
Default Constructor.
Class responsible for all message output.
virtual void Printf(EJournalLevel level, EJournalCategory category, const char *format,...) const
Method to print a formatted string.
#define IPOPTLIB_EXPORT
Definition: config.h:94
This file contains a base class for all exceptions and a set of macros to help with exceptions.
ipindex Index
Type of all indices of vectors, matrices etc.
Definition: IpTypes.hpp:20
EJournalLevel
Print Level Enum.