Ipopt 3.11.9
Loading...
Searching...
No Matches
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
19namespace 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),
67 line_number_(line_number),
68 type_(type)
69 {}
70
73 :
74 msg_(copy.msg_),
77 type_(copy.type_)
78 {}
79
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:
110
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
char * file_name
This is the base class for all exceptions.
IpoptException(std::string msg, std::string file_name, Index line_number, std::string type="IpoptException")
Constructor.
virtual ~IpoptException()
Default destructor.
const std::string & Message() const
void ReportException(const Journalist &jnlst, EJournalLevel level=J_ERROR) const
Method to report the exception to a journalist.
IpoptException(const IpoptException &copy)
Copy Constructor.
void operator=(const IpoptException &)
Overloaded Equals 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.
int Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:19
EJournalLevel
Print Level Enum.