-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
errors.cpp
102 lines (86 loc) · 3.48 KB
/
errors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
Copyright (C) 2003, 2004, 2005 StatPro Italia srl
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it
under the terms of the QuantLib license. You should have received a
copy of the license along with this program; if not, please email
<quantlib-dev@lists.sf.net>. The license is also available online at
<http://quantlib.org/license.shtml>.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
*/
#include <ql/errors.hpp>
#include <stdexcept>
namespace {
#if defined(_MSC_VER) || defined(__BORLANDC__)
// allow Visual Studio integration
std::string format(
#ifdef QL_ERROR_LINES
const std::string& file, long line,
#else
const std::string&, long,
#endif
#ifdef QL_ERROR_FUNCTIONS
const std::string& function,
#else
const std::string&,
#endif
const std::string& message) {
std::ostringstream msg;
#ifdef QL_ERROR_FUNCTIONS
if (function != "(unknown)")
msg << function << ": ";
#endif
#ifdef QL_ERROR_LINES
msg << "\n " << file << "(" << line << "): \n";
#endif
msg << message;
return msg.str();
}
#else
// use gcc format (e.g. for integration with Emacs)
std::string format(const std::string& file, long line,
const std::string& function,
const std::string& message) {
std::ostringstream msg;
#ifdef QL_ERROR_LINES
msg << "\n" << file << ":" << line << ": ";
#endif
#ifdef QL_ERROR_FUNCTIONS
if (function != "(unknown)")
msg << "In function `" << function << "': \n";
#endif
msg << message;
return msg.str();
}
#endif
}
namespace boost {
// must be defined by the user
void assertion_failed(char const * expr, char const * function,
char const * file, long line) {
throw std::runtime_error(format(file, line, function,
"Boost assertion failed: " +
std::string(expr)));
}
void assertion_failed_msg(char const * expr, char const * msg,
char const * function, char const * file,
long line) {
throw std::runtime_error(format(file, line, function,
"Boost assertion failed: " +
std::string(expr) + ": " +
std::string(msg)));
}
}
namespace QuantLib {
Error::Error(const std::string& file, long line,
const std::string& function,
const std::string& message) {
message_ = ext::make_shared<std::string>(
format(file, line, function, message));
}
const char* Error::what() const QL_NOEXCEPT { return message_->c_str(); }
}