DatException.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. UNKNOWN_EXCEPTION
  24. };
  25. class DatException : std::exception {
  26. public:
  27. DatException()
  28. : msg_(const_cast<char *>("Unknown DatException has been raised!"))
  29. , type_(UNKNOWN_EXCEPTION)
  30. {}
  31. explicit DatException(const char *msg, DAT_EXCEPTION_TYPE type = UNKNOWN_EXCEPTION) noexcept
  32. : std::exception()
  33. , type_(type)
  34. {
  35. msg_ = new char[strlen(msg) + 1];
  36. memcpy(msg_, msg, strlen(msg) + 1);
  37. #ifdef DAT_DEBUG
  38. fprintf(stderr, "%s\n", msg_);
  39. #endif
  40. }
  41. ~DatException() override
  42. {
  43. delete msg_;
  44. }
  45. const char* what() const noexcept override
  46. {
  47. return "DatException";
  48. }
  49. const DAT_EXCEPTION_TYPE type() const
  50. {
  51. return type_;
  52. }
  53. private:
  54. char *msg_;
  55. const DAT_EXCEPTION_TYPE type_;
  56. };
  57. }
  58. }
  59. #endif //LOTRO_DAT_PATCHER_DATEXCEPTION_H