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
11#ifndef __IPEXCEPTION_HPP__
12#define __IPEXCEPTION_HPP__
13
14#include "IpUtils.hpp"
15#include "IpJournalist.hpp"
16
17namespace Ipopt
18{
19
58{
59public:
62
64 const std::string& msg,
65 const std::string& file_name,
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
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
105private:
115
117
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
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.
#define IPOPTLIB_EXPORT
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.