summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/exception.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/shader_recompiler/exception.h40
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
12namespace Shader { 14namespace Shader {
13 15
14class LogicError : public std::logic_error { 16class Exception : public std::exception {
17public:
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
32private:
33 std::string message;
34};
35
36class LogicError : public Exception {
15public: 37public:
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
21class RuntimeError : public std::runtime_error { 43class RuntimeError : public Exception {
22public: 44public:
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
28class NotImplementedException : public std::logic_error { 50class NotImplementedException : public Exception {
29public: 51public:
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
35class InvalidArgument : public std::invalid_argument { 59class InvalidArgument : public Exception {
36public: 60public:
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