exception.h 1.7 KB

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