12 #include <hilti/rt/backtrace.h>
13 #include <hilti/rt/extension-points.h>
14 #include <hilti/rt/fmt.h>
46 : std::runtime_error(other),
47 _description(other._description),
48 _location(other._location),
49 _backtrace(other._backtrace) {}
51 Exception(Exception&&) noexcept = default;
52 Exception& operator=(const Exception& other) = default;
54 Exception& operator=(Exception&&) noexcept = default;
59 ~Exception() override;
65 const auto&
location()
const {
return _location; }
81 Exception(Internal,
const char* type, std::string_view desc);
82 Exception(Internal,
const char* type, std::string_view desc, std::string_view
location);
85 Exception(Internal,
const char* type, std::string_view what, std::string_view desc, std::string_view
location);
87 std::string _description;
88 std::string _location;
89 std::optional<Backtrace> _backtrace;
92 inline std::ostream& operator<<(std::ostream& stream,
const Exception& e) {
return stream << e.what(); }
94 #define HILTI_EXCEPTION(name, base) \
95 class name : public ::hilti::rt::base { \
97 name(std::string_view desc) : base(Internal(), #name, desc) {} \
98 name(std::string_view desc, std::string_view location) : base(Internal(), #name, desc, location) {} \
104 #define HILTI_EXCEPTION_NS(name, ns, base) \
105 class name : public ns::base { \
107 name(std::string_view desc) : base(Internal(), #name, desc) {} \
108 name(std::string_view desc, std::string_view location) : base(Internal(), #name, desc, location) {} \
114 #define HILTI_EXCEPTION_IMPL(name) name::name::~name() = default;
217 FormattingError(std::string desc) : RuntimeError(_sanitize(std::move(desc))) {}
220 std::string _sanitize(std::string desc) {
221 if (
auto pos = desc.find(
"tinyformat: "); pos != std::string::npos )
238 using std::runtime_error::runtime_error;
244 WouldBlock(std::string_view desc, std::string_view location);
247 namespace exception {
265 void printUncaught(
const Exception& e, std::ostream& out);
277 inline std::string what(
const std::exception& e) {
return e.what(); }
280 inline std::string where(
const Exception& e) {
return e.location(); }
284 namespace detail::adl {
285 inline std::string
to_string(
const Exception& e, adl::tag ) {
return fmt(
"<exception: %s>", e.what()); }
286 inline std::string
to_string(
const WouldBlock& e, adl::tag ) {
return fmt(
"<exception: %s>", e.what()); }
Definition: backtrace.h:15
Definition: exception.h:22
Exception(std::string_view desc, std::string_view location)
Definition: exception.h:37
const auto & description() const
Definition: exception.h:62
const auto & location() const
Definition: exception.h:65
const Backtrace * backtrace() const
Definition: exception.h:71
Exception(std::string_view desc)
Definition: exception.h:27
Definition: exception.h:236
WouldBlock(std::string_view desc, std::string_view location)
Definition: exception.cc:88
Definition: exception.h:250
HILTI_EXCEPTION(InvalidArgument, RuntimeError)
std::string fmt(const char *fmt, const Args &... args)
Definition: fmt.h:13
std::string to_string(T &&x)
Definition: extension-points.h:26