yuzu/src/shader_recompiler/exception.h

65 lines
1.7 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2021-01-08 22:30:07 -08:00
#pragma once
#include <exception>
2021-05-27 13:51:00 -07:00
#include <string>
2021-01-08 22:30:07 -08:00
#include <utility>
#include "common/logging/formatter.h"
2021-01-08 22:30:07 -08:00
namespace Shader {
2021-05-27 13:51:00 -07:00
class Exception : public std::exception {
public:
explicit Exception(std::string message) noexcept : err_message{std::move(message)} {}
2021-05-27 13:51:00 -07:00
[[nodiscard]] const char* what() const noexcept override {
return err_message.c_str();
2021-05-27 13:51:00 -07:00
}
void Prepend(std::string_view prepend) {
err_message.insert(0, prepend);
2021-05-27 13:51:00 -07:00
}
void Append(std::string_view append) {
err_message += append;
2021-05-27 13:51:00 -07:00
}
private:
std::string err_message;
2021-05-27 13:51:00 -07:00
};
class LogicError : public Exception {
2021-01-08 22:30:07 -08:00
public:
template <typename... Args>
explicit LogicError(const char* message, Args&&... args)
2021-06-28 20:44:03 -07:00
: Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {}
2021-01-08 22:30:07 -08:00
};
2021-05-27 13:51:00 -07:00
class RuntimeError : public Exception {
2021-01-08 22:30:07 -08:00
public:
template <typename... Args>
explicit RuntimeError(const char* message, Args&&... args)
2021-06-28 20:44:03 -07:00
: Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {}
2021-01-08 22:30:07 -08:00
};
2021-05-27 13:51:00 -07:00
class NotImplementedException : public Exception {
2021-01-08 22:30:07 -08:00
public:
template <typename... Args>
explicit NotImplementedException(const char* message, Args&&... args)
2021-06-28 20:44:03 -07:00
: Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {
2021-05-27 13:51:00 -07:00
Append(" is not implemented");
}
2021-01-08 22:30:07 -08:00
};
2021-05-27 13:51:00 -07:00
class InvalidArgument : public Exception {
2021-01-08 22:30:07 -08:00
public:
template <typename... Args>
explicit InvalidArgument(const char* message, Args&&... args)
2021-06-28 20:44:03 -07:00
: Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {}
2021-01-08 22:30:07 -08:00
};
} // namespace Shader