HdfException.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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) : type(type),
  10. classType(classType),
  11. exceptionType(OTHER),
  12. message(exceptionMessagePrefix + message) {}
  13. HdfException(const Type& type, const ClassType& classType, const ExceptionType& exceptionType) : type(type),
  14. classType(classType),
  15. exceptionType(exceptionType),
  16. message(exceptionMessagePrefix + exceptionTypeMap.at(exceptionType)) {}
  17. /// Get the Type of the object which threw the exception.
  18. Type getType() const noexcept;
  19. /// Get the ClassType of the object which threw the exception.
  20. ClassType getClassType() const noexcept;
  21. /// Get the ExceptionType of the object which threw the exception.
  22. ExceptionType getExceptionType() const noexcept;
  23. /// Get the message of the exception.
  24. std::string getMessage() const noexcept;
  25. /// Get the exception message.
  26. /// Returns the same string (but in c string type) which is returned by the getMessage() function.
  27. const char *what() const noexcept {
  28. return message.data();
  29. }
  30. private:
  31. /// Exception message prefix
  32. static const std::string exceptionMessagePrefix;
  33. /// Associates the exception type with a specific message
  34. /// \note All the exception types must have a message associated with
  35. static const std::map<ExceptionType, std::string> exceptionTypeMap;
  36. Type type;
  37. ClassType classType;
  38. ExceptionType exceptionType;
  39. std::string message;
  40. };
  41. }
  42. #endif //HDF4CPP_HDFEXCEPTION_H