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