Exception.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 _FASTCDR_EXCEPTIONS_EXCEPTION_H_
  15. #define _FASTCDR_EXCEPTIONS_EXCEPTION_H_
  16. #include "../fastcdr_dll.h"
  17. #include <string>
  18. #include <exception>
  19. namespace eprosima
  20. {
  21. namespace fastcdr
  22. {
  23. namespace exception
  24. {
  25. /*!
  26. * @brief This abstract class is used to create exceptions.
  27. * @ingroup EXCEPTIONMODULE
  28. */
  29. class Exception : public std::exception
  30. {
  31. public:
  32. //! \brief Default destructor.
  33. virtual Cdr_DllAPI ~Exception() noexcept;
  34. //! \brief This function throws the object as exception.
  35. virtual Cdr_DllAPI void raise() const = 0;
  36. /*!
  37. * @brief This function returns the error message.
  38. *
  39. * @return The error message.
  40. */
  41. virtual Cdr_DllAPI const char* what() const noexcept ;
  42. protected:
  43. /*!
  44. * @brief Default constructor.
  45. *
  46. * @param message A error message. This message pointer is copied.
  47. */
  48. Cdr_DllAPI Exception(const char* const &message) noexcept;
  49. /*!
  50. * @brief Default copy constructor.
  51. *
  52. * @param ex Exception that will be copied.
  53. */
  54. Cdr_DllAPI Exception(const Exception &ex) noexcept;
  55. #if HAVE_CXX0X
  56. /*!
  57. * @brief Default move constructor.
  58. *
  59. * @param ex Exception that will be moved.
  60. */
  61. Cdr_DllAPI Exception(Exception&& ex) noexcept;
  62. #endif
  63. /*!
  64. * @brief Assigment operation.
  65. *
  66. * @param ex Exception that will be copied.
  67. */
  68. Cdr_DllAPI Exception& operator=(const Exception &ex) noexcept;
  69. #if HAVE_CXX0X
  70. /*!
  71. * @brief Assigment operation.
  72. *
  73. * @param ex Exception that will be moved.
  74. */
  75. Cdr_DllAPI Exception& operator=(Exception&&) noexcept;
  76. #endif
  77. private:
  78. const char* m_message;
  79. };
  80. } //namespace exception
  81. } //namespace fastcdr
  82. } //namespace eprosima
  83. #endif // _FASTCDR_EXCEPTIONS_EXCEPTION_H_