DatException.h 1.6 KB

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