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