DatException.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // Created by Иван_Архипов on 31.10.2017.
  3. //
  4. #ifndef LOTRO_DAT_PATCHER_DATEXCEPTION_H
  5. #define LOTRO_DAT_PATCHER_DATEXCEPTION_H
  6. #define DAT_DEBUG
  7. #include <string>
  8. #include <iostream>
  9. #include <cstring>
  10. extern "C++"
  11. {
  12. namespace LOTRO_DAT
  13. {
  14. enum DAT_EXCEPTION_TYPE {
  15. INIT_EXCEPTION,
  16. READ_EXCEPTION,
  17. WRITE_EXCEPTION,
  18. SUBDIR_EXCEPTION,
  19. SUBFILE_EXCEPTION,
  20. IMPORT_EXCEPTION,
  21. EXPORT_EXCEPTION,
  22. DATA_EXCEPTION,
  23. DATABASE_EXCEPTION,
  24. UNKNOWN_EXCEPTION
  25. };
  26. class DatException : std::exception {
  27. public:
  28. DatException()
  29. : msg_(const_cast<char *>("Unknown DatException has been raised!"))
  30. , type_(UNKNOWN_EXCEPTION)
  31. {}
  32. explicit DatException(const char *msg, DAT_EXCEPTION_TYPE type = UNKNOWN_EXCEPTION) noexcept
  33. : std::exception()
  34. , type_(type)
  35. {
  36. msg_ = new char[strlen(msg) + 1];
  37. memcpy(msg_, msg, strlen(msg) + 1);
  38. #ifdef DAT_DEBUG
  39. fprintf(stderr, "%s\n", msg_);
  40. #endif
  41. }
  42. ~DatException() override
  43. {
  44. delete msg_;
  45. }
  46. const char* what() const noexcept override
  47. {
  48. return "DatException";
  49. }
  50. const DAT_EXCEPTION_TYPE type() const
  51. {
  52. return type_;
  53. }
  54. private:
  55. char *msg_;
  56. const DAT_EXCEPTION_TYPE type_;
  57. };
  58. }
  59. }
  60. #endif //LOTRO_DAT_PATCHER_DATEXCEPTION_H