diff options
Diffstat (limited to 'src/shader_recompiler/exception.h')
| -rw-r--r-- | src/shader_recompiler/exception.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/shader_recompiler/exception.h b/src/shader_recompiler/exception.h new file mode 100644 index 000000000..337e7f0c8 --- /dev/null +++ b/src/shader_recompiler/exception.h | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <stdexcept> | ||
| 8 | #include <string> | ||
| 9 | #include <string_view> | ||
| 10 | #include <utility> | ||
| 11 | |||
| 12 | #include <fmt/format.h> | ||
| 13 | |||
| 14 | namespace Shader { | ||
| 15 | |||
| 16 | class Exception : public std::exception { | ||
| 17 | public: | ||
| 18 | explicit Exception(std::string message) noexcept : err_message{std::move(message)} {} | ||
| 19 | |||
| 20 | const char* what() const noexcept override { | ||
| 21 | return err_message.c_str(); | ||
| 22 | } | ||
| 23 | |||
| 24 | void Prepend(std::string_view prepend) { | ||
| 25 | err_message.insert(0, prepend); | ||
| 26 | } | ||
| 27 | |||
| 28 | void Append(std::string_view append) { | ||
| 29 | err_message += append; | ||
| 30 | } | ||
| 31 | |||
| 32 | private: | ||
| 33 | std::string err_message; | ||
| 34 | }; | ||
| 35 | |||
| 36 | class LogicError : public Exception { | ||
| 37 | public: | ||
| 38 | template <typename... Args> | ||
| 39 | LogicError(const char* message, Args&&... args) | ||
| 40 | : Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {} | ||
| 41 | }; | ||
| 42 | |||
| 43 | class RuntimeError : public Exception { | ||
| 44 | public: | ||
| 45 | template <typename... Args> | ||
| 46 | RuntimeError(const char* message, Args&&... args) | ||
| 47 | : Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {} | ||
| 48 | }; | ||
| 49 | |||
| 50 | class NotImplementedException : public Exception { | ||
| 51 | public: | ||
| 52 | template <typename... Args> | ||
| 53 | NotImplementedException(const char* message, Args&&... args) | ||
| 54 | : Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} { | ||
| 55 | Append(" is not implemented"); | ||
| 56 | } | ||
| 57 | }; | ||
| 58 | |||
| 59 | class InvalidArgument : public Exception { | ||
| 60 | public: | ||
| 61 | template <typename... Args> | ||
| 62 | InvalidArgument(const char* message, Args&&... args) | ||
| 63 | : Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {} | ||
| 64 | }; | ||
| 65 | |||
| 66 | } // namespace Shader | ||