HdfException.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /// \copyright Copyright (c) Catalysts GmbH
  2. /// \author Patrik Kovacs, Catalysts GmbH
  3. #ifndef HDF4CPP_HDFEXCEPTION_H
  4. #define HDF4CPP_HDFEXCEPTION_H
  5. #include <hdf4cpp/HdfDefines.h>
  6. namespace hdf4cpp {
  7. class HdfException : public std::exception {
  8. public:
  9. HdfException(const Type &type, const ClassType &classType, const std::string &message)
  10. : type(type)
  11. , classType(classType)
  12. , exceptionType(OTHER)
  13. , message(exceptionMessagePrefix + message) {
  14. }
  15. HdfException(const Type &type, const ClassType &classType, const ExceptionType &exceptionType)
  16. : type(type)
  17. , classType(classType)
  18. , exceptionType(exceptionType)
  19. , message(exceptionMessagePrefix + exceptionTypeMap.at(exceptionType)) {
  20. }
  21. /// Get the Type of the object which threw the exception.
  22. Type getType() const noexcept;
  23. /// Get the ClassType of the object which threw the exception.
  24. ClassType getClassType() const noexcept;
  25. /// Get the ExceptionType of the object which threw the exception.
  26. ExceptionType getExceptionType() const noexcept;
  27. /// Get the message of the exception.
  28. std::string getMessage() const noexcept;
  29. /// Get the exception message.
  30. /// Returns the same string (but in c string type) which is returned by the getMessage() function.
  31. const char *what() const noexcept {
  32. return message.data();
  33. }
  34. private:
  35. /// Exception message prefix
  36. static const std::string exceptionMessagePrefix;
  37. /// Associates the exception type with a specific message
  38. /// \note All the exception types must have a message associated with
  39. static const std::map<ExceptionType, std::string> exceptionTypeMap;
  40. Type type;
  41. ClassType classType;
  42. ExceptionType exceptionType;
  43. std::string message;
  44. };
  45. }
  46. #endif // HDF4CPP_HDFEXCEPTION_H