Ipopt Documentation  
 
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// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6//
7// This file contains a base class for all exceptions and a set of macros to help with exceptions.
8
9#ifndef __IPEXCEPTION_HPP__
10#define __IPEXCEPTION_HPP__
11
12#include "IpUtils.hpp"
13#include "IpJournalist.hpp"
14
15/* for the exception classes, __attribute__((__visibility__("default"))) needs to be used
16 * also by libraries that link against an Ipopt shared library on macOS/clang,
17 * since otherwise the exceptions cannot be recognized by a catch() in the user code
18 * (https://stackoverflow.com/questions/11913151/catching-derived-exceptions-types-fails-on-clang-macos-x)
19 */
20#if defined(__GNUC__) && __GNUC__ >= 4
21#define IPOPTEXCEPTION_EXPORT __attribute__((__visibility__("default")))
22#else
23#define IPOPTEXCEPTION_EXPORT IPOPTLIB_EXPORT
24#endif
25
26namespace Ipopt
27{
28
67{
68public:
71
73 const std::string& msg,
74 const std::string& file_name,
76 const std::string& type = "IpoptException"
77 )
78 : msg_(msg),
79 file_name_(file_name),
80 line_number_(line_number),
81 type_(type)
82 { }
83
86 const IpoptException& copy
87 )
88 : msg_(copy.msg_),
89 file_name_(copy.file_name_),
90 line_number_(copy.line_number_),
91 type_(copy.type_)
92 { }
93
96 { }
98
101 const Journalist& jnlst,
102 EJournalLevel level = J_ERROR
103 ) const
104 {
105 jnlst.Printf(level, J_MAIN,
106 "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());
107 }
108
109 const std::string& Message() const
110 {
111 return msg_;
112 }
113
114private:
124
126
129 const IpoptException&
130 );
132
133 std::string msg_;
134 std::string file_name_;
136 std::string type_;
137};
138
139} // namespace Ipopt
140
141#define THROW_EXCEPTION(__except_type, __msg) \
142 throw __except_type( (__msg), (__FILE__), (__LINE__) );
143
144#define ASSERT_EXCEPTION(__condition, __except_type, __msg) \
145 if (! (__condition) ) { \
146 std::string newmsg = #__condition; \
147 newmsg += " evaluated false: "; \
148 newmsg += __msg; \
149 throw __except_type( (newmsg), (__FILE__), (__LINE__) ); \
150 }
151
152#define DECLARE_STD_EXCEPTION(__except_type) \
153 class IPOPTEXCEPTION_EXPORT __except_type : public Ipopt::IpoptException \
154 { \
155 public: \
156 __except_type(const std::string& msg, const std::string& fname, Ipopt::Index line) \
157 : Ipopt::IpoptException(msg,fname,line, #__except_type) {} \
158 __except_type(const __except_type& copy) \
159 : Ipopt::IpoptException(copy) {} \
160 private: \
161 __except_type(); \
162 void operator=(const __except_type&); \
163 }
164
165#endif
#define IPOPTEXCEPTION_EXPORT
#define IPOPT_INDEX_FORMAT
Format specifier to use for ipindex in printf-format strings.
Definition IpTypes.h:72
Templated class which stores one entry for the CachedResult class.
This is the base class for all exceptions.
IpoptException(const std::string &msg, const std::string &file_name, Index line_number, const 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 &)
Default Assignment Operator.
IpoptException()
Default Constructor.
Class responsible for all message output.
ipindex Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:20
EJournalLevel
Print Level Enum.