yuzu/src/shader_recompiler/exception.h

67 lines
1.6 KiB
C++
Raw Normal View History

2021-01-09 09:30:07 +03:00
// Copyright 2021 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <stdexcept>
2021-05-27 23:51:00 +03:00
#include <string>
#include <string_view>
2021-01-09 09:30:07 +03:00
#include <utility>
#include <fmt/format.h>
namespace Shader {
2021-05-27 23:51:00 +03:00
class Exception : public std::exception {
public:
explicit Exception(std::string message_) noexcept : message{std::move(message_)} {}
const char* what() const override {
return message.c_str();
}
void Prepend(std::string_view prepend) {
message.insert(0, prepend);
}
void Append(std::string_view append) {
message += append;
}
private:
std::string message;
};
class LogicError : public Exception {
2021-01-09 09:30:07 +03:00
public:
template <typename... Args>
LogicError(const char* message, Args&&... args)
2021-05-27 23:51:00 +03:00
: Exception{fmt::format(message, std::forward<Args>(args)...)} {}
2021-01-09 09:30:07 +03:00
};
2021-05-27 23:51:00 +03:00
class RuntimeError : public Exception {
2021-01-09 09:30:07 +03:00
public:
template <typename... Args>
RuntimeError(const char* message, Args&&... args)
2021-05-27 23:51:00 +03:00
: Exception{fmt::format(message, std::forward<Args>(args)...)} {}
2021-01-09 09:30:07 +03:00
};
2021-05-27 23:51:00 +03:00
class NotImplementedException : public Exception {
2021-01-09 09:30:07 +03:00
public:
template <typename... Args>
NotImplementedException(const char* message, Args&&... args)
2021-05-27 23:51:00 +03:00
: Exception{fmt::format(message, std::forward<Args>(args)...)} {
Append(" is not implemented");
}
2021-01-09 09:30:07 +03:00
};
2021-05-27 23:51:00 +03:00
class InvalidArgument : public Exception {
2021-01-09 09:30:07 +03:00
public:
template <typename... Args>
InvalidArgument(const char* message, Args&&... args)
2021-05-27 23:51:00 +03:00
: Exception{fmt::format(message, std::forward<Args>(args)...)} {}
2021-01-09 09:30:07 +03:00
};
} // namespace Shader