Exception.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include <windows.h>
  3. #include "xstring.hpp"
  4. #include <vector>
  5. namespace nkg {
  6. class Exception {
  7. private:
  8. PCTSTR _SourceFile;
  9. SIZE_T _SourceLine;
  10. PCTSTR _Message;
  11. std::vector<std::xstring> _Hints;
  12. public:
  13. Exception(PCTSTR SourceFile, SIZE_T SourceLine, PCTSTR CustomMessage) noexcept :
  14. _SourceFile(SourceFile),
  15. _SourceLine(SourceLine),
  16. _Message(CustomMessage) {}
  17. [[nodiscard]]
  18. auto File() const noexcept {
  19. return _SourceFile;
  20. }
  21. [[nodiscard]]
  22. auto Line() const noexcept {
  23. return _SourceLine;
  24. }
  25. [[nodiscard]]
  26. auto Message() const noexcept {
  27. return _Message;
  28. }
  29. auto& AddHint(const std::xstring& Hint) {
  30. _Hints.emplace_back(Hint);
  31. return *this;
  32. }
  33. [[nodiscard]]
  34. const auto& Hints() const noexcept {
  35. return _Hints;
  36. }
  37. [[nodiscard]]
  38. virtual bool HasErrorCode() const noexcept {
  39. return false;
  40. }
  41. [[nodiscard]]
  42. virtual ULONG_PTR ErrorCode() const noexcept {
  43. return 0;
  44. }
  45. [[nodiscard]]
  46. virtual PCTSTR ErrorString() const noexcept {
  47. return nullptr;
  48. }
  49. virtual ~Exception() = default;
  50. };
  51. }