25#ifndef quantlib_errors_hpp
26#define quantlib_errors_hpp
30#include <boost/assert.hpp>
31#include <boost/current_function.hpp>
39 class Error :
public std::exception {
44 Error(
const std::string& file,
46 const std::string& functionName,
47 const std::string& message =
"");
49 const char*
what()
const noexcept override;
57#define QL_MULTILINE_FAILURE_BEGIN do {
62#if defined(BOOST_MSVC)
63 #define QL_MULTILINE_FAILURE_END \
64 __pragma(warning(push)) \
65 __pragma(warning(disable:4127)) \
67 __pragma(warning(pop))
69 #define QL_MULTILINE_FAILURE_END } while(false)
73#define QL_MULTILINE_ASSERTION_BEGIN do {
78#if defined(BOOST_MSVC)
79 #define QL_MULTILINE_ASSERTION_END \
80 __pragma(warning(push)) \
81 __pragma(warning(disable:4127)) \
83 __pragma(warning(pop))
85 #define QL_MULTILINE_ASSERTION_END } while(false)
92#define QL_FAIL(message) \
93QL_MULTILINE_FAILURE_BEGIN \
94 std::ostringstream _ql_msg_stream; \
95 _ql_msg_stream << message; \
96 throw QuantLib::Error(__FILE__,__LINE__, \
97 BOOST_CURRENT_FUNCTION,_ql_msg_stream.str()); \
98QL_MULTILINE_FAILURE_END
104#define QL_ASSERT(condition,message) \
105QL_MULTILINE_ASSERTION_BEGIN \
107 std::ostringstream _ql_msg_stream; \
108 _ql_msg_stream << message; \
109 throw QuantLib::Error(__FILE__,__LINE__, \
110 BOOST_CURRENT_FUNCTION,_ql_msg_stream.str()); \
112QL_MULTILINE_ASSERTION_END
117#define QL_REQUIRE(condition,message) \
118QL_MULTILINE_ASSERTION_BEGIN \
120 std::ostringstream _ql_msg_stream; \
121 _ql_msg_stream << message; \
122 throw QuantLib::Error(__FILE__,__LINE__, \
123 BOOST_CURRENT_FUNCTION,_ql_msg_stream.str()); \
125QL_MULTILINE_ASSERTION_END
130#define QL_ENSURE(condition,message) \
131QL_MULTILINE_ASSERTION_BEGIN \
133 std::ostringstream _ql_msg_stream; \
134 _ql_msg_stream << message; \
135 throw QuantLib::Error(__FILE__,__LINE__, \
136 BOOST_CURRENT_FUNCTION,_ql_msg_stream.str()); \
138QL_MULTILINE_ASSERTION_END
ext::shared_ptr< std::string > message_
const char * what() const noexcept override
returns the error message.
Global definitions and compiler switches.
Maps shared_ptr to either the boost or std implementation.