exception.h 1.7 KB

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