Exceptions
| 48 | |
| 49 | // Exceptions |
| 50 | class exception final : public std::exception { |
| 51 | std::size_t mLine = 0; |
| 52 | std::string mFile, mCode, mWhat, mStr; |
| 53 | |
| 54 | static std::string compose_what(const std::string &file, std::size_t line, const std::string &code, const std::string &what) |
| 55 | { |
| 56 | return "File \"" + file + "\", line " + std::to_string(line) + ": " + what + "\n>\t" + code + "\n"; |
| 57 | } |
| 58 | |
| 59 | static std::string compose_what_internal(const std::string &file, const std::string &what) |
| 60 | { |
| 61 | return "File \"" + file + "\", line <INTERNAL>: " + what + "\n"; |
| 62 | } |
| 63 | |
| 64 | public: |
| 65 | exception() = delete; |
| 66 | |
| 67 | exception(std::size_t line, std::string file, std::string code, std::string what) noexcept : mLine(line), mFile(std::move(file)), mCode(std::move(code)), mWhat(std::move(what)) |
| 68 | { |
| 69 | mStr = compose_what(mFile, mLine, mCode, mWhat); |
| 70 | } |
| 71 | |
| 72 | exception(const exception &) = default; |
| 73 | |
| 74 | exception(exception &&) noexcept = default; |
| 75 | |
| 76 | ~exception() override = default; |
| 77 | |
| 78 | exception &operator=(const exception &) = default; |
| 79 | |
| 80 | exception &operator=(exception &&) = default; |
| 81 | |
| 82 | const std::string &file() const noexcept |
| 83 | { |
| 84 | return mFile; |
| 85 | } |
| 86 | |
| 87 | void relocate_to_csym(const csym_info &); |
| 88 | |
| 89 | const char *what() const noexcept override |
| 90 | { |
| 91 | return this->mStr.c_str(); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | class compile_error final : public std::exception { |
| 96 | std::string mWhat = "Compile Error"; |
nothing calls this directly
no outgoing calls
no test coverage detected