ExceptionSystem.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <windows.h>
  3. #include "Exception.hpp"
  4. class SystemException : public Exception {
  5. private:
  6. DWORD _ErrorCode;
  7. TString _ErrorString;
  8. public:
  9. template<typename... __Ts>
  10. SystemException(const TString& FileName,
  11. size_t LineNumber,
  12. DWORD Win32ErrorCode,
  13. const TString& CustomMsg,
  14. __Ts&&... SomeHints) noexcept :
  15. Exception(FileName, LineNumber, CustomMsg, std::forward<__Ts>(SomeHints)...),
  16. _ErrorCode(Win32ErrorCode)
  17. {
  18. PTSTR Text = NULL;
  19. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK,
  20. NULL,
  21. Win32ErrorCode,
  22. MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
  23. reinterpret_cast<PTSTR>(&Text),
  24. 0,
  25. NULL);
  26. _ErrorString.assign(Text);
  27. LocalFree(Text);
  28. }
  29. virtual bool HasErrorCode() const noexcept override {
  30. return true;
  31. }
  32. virtual uintptr_t ErrorCode() const noexcept override {
  33. return _ErrorCode;
  34. }
  35. virtual const TString& ErrorString() const noexcept override {
  36. return _ErrorString;
  37. }
  38. };