12 #include <hilti/rt/backtrace.h>
13 #include <hilti/rt/extension-points.h>
14 #include <hilti/rt/fmt.h>
48 : std::runtime_error(other),
49 _description(other._description),
50 _location(other._location),
51 _backtrace(other._backtrace) {}
53 Exception(Exception&&) noexcept = default;
54 Exception& operator=(const Exception& other) = default;
56 Exception& operator=(Exception&&) noexcept = default;
61 ~Exception() override;
67 std::string_view
location()
const {
return _location; }
83 Exception(Internal,
const char* type, std::string_view desc);
84 Exception(Internal,
const char* type, std::string_view desc, std::string_view
location);
87 Exception(Internal,
const char* type, std::string_view what, std::string_view desc, std::string_view
location);
89 std::string _description;
90 std::string _location;
91 std::optional<Backtrace> _backtrace;
94 inline std::ostream& operator<<(std::ostream& stream,
const Exception& e) {
return stream << e.what(); }
96 #define HILTI_EXCEPTION(name, base) \
97 class name : public ::hilti::rt::base { \
99 name(std::string_view desc) : base(Internal(), #name, desc) {} \
100 name(std::string_view desc, std::string_view location) : base(Internal(), #name, desc, location) {} \
103 name(const name&) = default; \
104 name(name&&) = default; \
106 name& operator=(const name&) = default; \
107 name& operator=(name&&) = default; \
113 #define HILTI_EXCEPTION_NS(name, ns, base) \
114 class name : public ns::base { \
116 name(std::string_view desc) : base(Internal(), #name, desc) {} \
117 name(std::string_view desc, std::string_view location) : base(Internal(), #name, desc, location) {} \
124 #define HILTI_EXCEPTION_IMPL(name) name::name::~name() = default;
227 FormattingError(std::string desc) : RuntimeError(_sanitize(std::move(desc))) {}
230 std::string _sanitize(std::string desc) {
231 if (
auto pos = desc.find(
"tinyformat: "); pos != std::string::npos )
248 using std::runtime_error::runtime_error;
257 namespace exception {
275 void printUncaught(
const Exception& e, std::ostream& out);
287 String what(
const std::exception& e);
294 namespace detail::adl {
295 inline std::string
to_string(
const Exception& e, adl::tag ) {
return fmt(
"<exception: %s>", e.what()); }
296 inline std::string
to_string(
const WouldBlock& e, adl::tag ) {
return fmt(
"<exception: %s>", e.what()); }
Definition: backtrace.h:17
Definition: exception.h:24
std::string_view description() const
Definition: exception.h:64
Exception(std::string_view desc, std::string_view location)
Definition: exception.h:39
const Backtrace * backtrace() const
Definition: exception.h:73
Exception(std::string_view desc)
Definition: exception.h:29
std::string_view location() const
Definition: exception.h:67
Definition: exception.h:246
WouldBlock(std::string_view desc, std::string_view location)
Definition: exception.cc:98
Definition: exception.h:260
HILTI_EXCEPTION(InvalidArgument, RuntimeError)
void location(const char *x)
Definition: logging.h:126
std::string fmt(const char *fmt, const Args &... args)
Definition: fmt.h:17
std::string to_string(T &&x)
Definition: extension-points.h:26