DatException.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "EasyLogging++/easylogging++.h"
  11. extern "C++"
  12. {
  13. namespace LOTRO_DAT
  14. {
  15. enum DAT_EXCEPTION_TYPE {
  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 : public std::exception {
  27. public:
  28. DatException()
  29. : msg_(const_cast<char *>("Unknown DatException has been raised!"))
  30. , type_(UNKNOWN_EXCEPTION)
  31. {
  32. LOG(ERROR) << "THROWN DatException " << std::string(msg_);
  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. LOG(ERROR) << "THROWN DatException " << std::string(msg_);
  41. #ifdef DAT_DEBUG
  42. fprintf(stderr, "%s\n", msg_);
  43. #endif
  44. }
  45. ~DatException() override
  46. {
  47. delete[] msg_;
  48. }
  49. const char* what() const noexcept override
  50. {
  51. return (std::string("DatException ") + std::string(msg_)).c_str();
  52. }
  53. DAT_EXCEPTION_TYPE type() const
  54. {
  55. return type_;
  56. }
  57. private:
  58. char *msg_;
  59. const DAT_EXCEPTION_TYPE type_;
  60. };
  61. }
  62. }
  63. #endif //LOTRO_DAT_PATCHER_DATEXCEPTION_H