pineapple-src/src/shader_recompiler/exception.h

65 lines
1.7 KiB
C
Raw Normal View History

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