Line |
Branch |
Exec |
Source |
1 |
|
|
#pragma once |
2 |
|
|
|
3 |
|
|
#include <exception> |
4 |
|
|
|
5 |
|
|
// |
6 |
|
|
#include "compatibility/compatibility.h" |
7 |
|
|
#include "dependencies/fmt.h" |
8 |
|
|
|
9 |
|
|
namespace lython { |
10 |
|
|
|
11 |
|
|
// Exception that shows the backtrace when .what() is called |
12 |
|
|
class Exception: public std::exception { |
13 |
|
|
public: |
14 |
|
|
template <typename... Args> |
15 |
|
|
Exception(FmtStr fmt, String const& name, const Args&... args): |
16 |
|
✗ |
message(fmtstr(fmt, name, args...)) {} |
17 |
|
|
|
18 |
|
|
const char* what() const LY_NOEXCEPT final { |
19 |
|
✗ |
spdlog_log(LogLevel::Error, fmt::format("Exception raised: {}", message)); |
20 |
|
✗ |
show_backtrace(); |
21 |
|
✗ |
return message.c_str(); |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
private: |
25 |
|
|
String message; |
26 |
|
|
}; |
27 |
|
|
|
28 |
|
|
// Make a simple exception |
29 |
|
|
#define NEW_EXCEPTION(name) \ |
30 |
|
|
class name: public Exception { \ |
31 |
|
|
public: \ |
32 |
|
|
template <typename... Args> \ |
33 |
|
|
name(FmtStr fmtstr, const Args&... args): Exception(fmtstr, String(#name), args...) {} \ |
34 |
|
|
}; |
35 |
|
|
|
36 |
|
|
} // namespace lython |
37 |
|
|
|