Exception.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef _FASTDDS_RTPS_EXCEPTIONS_EXCEPTION_H_
  15. #define _FASTDDS_RTPS_EXCEPTIONS_EXCEPTION_H_
  16. #include <fastrtps/fastrtps_dll.h>
  17. #include <exception>
  18. #include <string>
  19. #include <cstdint>
  20. #undef minor
  21. namespace eprosima {
  22. namespace fastrtps {
  23. namespace rtps {
  24. /**
  25. * @brief This abstract class is used to create exceptions.
  26. * @ingroup EXCEPTIONMODULE
  27. */
  28. class Exception : public std::exception
  29. {
  30. public:
  31. RTPS_DllAPI Exception(){};
  32. /// @brief Default destructor.
  33. virtual RTPS_DllAPI ~Exception() throw();
  34. /**
  35. * @brief This function returns the number associated with the system exception.
  36. * @return The number associated with the system exception.
  37. */
  38. RTPS_DllAPI const int32_t& minor() const;
  39. /**
  40. * @brief This function sets the number that will be associated with the system exception.
  41. * @param minor The number that will be associated with the system exception.
  42. */
  43. RTPS_DllAPI void minor(const int32_t &minor);
  44. /// @brief This function throws the object as exception.
  45. virtual RTPS_DllAPI void raise() const = 0;
  46. /**
  47. * @brief This function returns the error message.
  48. * @return The error message.
  49. */
  50. virtual RTPS_DllAPI const char* what() const throw();
  51. protected:
  52. /**
  53. * @brief Default constructor.
  54. */
  55. RTPS_DllAPI explicit Exception(const char* const& message);
  56. /**
  57. * @brief Default copy constructor.
  58. * @param ex Exception that will be copied.
  59. */
  60. RTPS_DllAPI Exception(const Exception &ex);
  61. /**
  62. * @brief Default move constructor.
  63. * @param ex Exception that will be moved.
  64. */
  65. RTPS_DllAPI Exception(Exception&& ex);
  66. /**
  67. * @brief Constructor.
  68. * @param message An error message. This message is copied.
  69. * @param minor The number that will be associated with the system exception.
  70. */
  71. RTPS_DllAPI explicit Exception(const char* const& message, const int32_t minor);
  72. /**
  73. * @brief Assigment operation.
  74. * @param ex Exception that will be copied.
  75. */
  76. RTPS_DllAPI Exception& operator=(const Exception& ex);
  77. /**
  78. * @brief Assigment operation.
  79. * @param ex Exception that will be moved.
  80. */
  81. RTPS_DllAPI Exception& operator=(Exception&& ex);
  82. private:
  83. std::string message_;
  84. int32_t minor_;
  85. };
  86. } // namespace rtps
  87. } // namespace fastrtps
  88. } // namespace eprosima
  89. #endif // _FASTDDS_RTPS_EXCEPTIONS_EXCEPTION_H_