ExceptionKeystone.hpp 943 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include <Exception.hpp>
  3. #include <keystone/keystone.h>
  4. namespace nkg {
  5. class KeystoneError final : public Exception {
  6. private:
  7. ks_err _ErrorCode;
  8. std::xstring _ErrorString;
  9. public:
  10. KeystoneError(PCTSTR SourceFile, SIZE_T SourceLine, ks_err KeystoneErrorCode, PCTSTR CustomMessage) noexcept :
  11. Exception(SourceFile, SourceLine, CustomMessage),
  12. _ErrorCode(KeystoneErrorCode),
  13. _ErrorString(std::xstring_extension{}, ks_strerror(KeystoneErrorCode), CP_UTF8) {}
  14. [[nodiscard]]
  15. virtual bool HasErrorCode() const noexcept override {
  16. return true;
  17. }
  18. [[nodiscard]]
  19. virtual ULONG_PTR ErrorCode() const noexcept override {
  20. return _ErrorCode;
  21. }
  22. [[nodiscard]]
  23. virtual PCTSTR ErrorString() const noexcept override {
  24. return _ErrorString.c_str();
  25. }
  26. };
  27. }