exception.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <exception>
  5. #include <string>
  6. #include <utility>
  7. #include "common/logging/formatter.h"
  8. namespace Shader {
  9. class Exception : public std::exception {
  10. public:
  11. explicit Exception(std::string message) noexcept : err_message{std::move(message)} {}
  12. [[nodiscard]] const char* what() const noexcept override {
  13. return err_message.c_str();
  14. }
  15. void Prepend(std::string_view prepend) {
  16. err_message.insert(0, prepend);
  17. }
  18. void Append(std::string_view append) {
  19. err_message += append;
  20. }
  21. private:
  22. std::string err_message;
  23. };
  24. class LogicError : public Exception {
  25. public:
  26. template <typename... Args>
  27. explicit LogicError(const char* message, Args&&... args)
  28. : Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {}
  29. };
  30. class RuntimeError : public Exception {
  31. public:
  32. template <typename... Args>
  33. explicit RuntimeError(const char* message, Args&&... args)
  34. : Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {}
  35. };
  36. class NotImplementedException : public Exception {
  37. public:
  38. template <typename... Args>
  39. explicit NotImplementedException(const char* message, Args&&... args)
  40. : Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {
  41. Append(" is not implemented");
  42. }
  43. };
  44. class InvalidArgument : public Exception {
  45. public:
  46. template <typename... Args>
  47. explicit InvalidArgument(const char* message, Args&&... args)
  48. : Exception{fmt::format(fmt::runtime(message), std::forward<Args>(args)...)} {}
  49. };
  50. } // namespace Shader