src/utilities/core/Exception.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_CORE_EXCEPTION_HPP | ||
| 7 | #define UTILITIES_CORE_EXCEPTION_HPP | ||
| 8 | |||
| 9 | #include <string> | ||
| 10 | #include <exception> | ||
| 11 | #include "../UtilitiesAPI.hpp" | ||
| 12 | |||
| 13 | namespace openstudio { | ||
| 14 | |||
| 15 | /** Base class for exceptions. */ | ||
| 16 | class UTILITIES_API Exception : public std::exception | ||
| 17 | { | ||
| 18 | public: | ||
| 19 | /// Constructor takes a message | ||
| 20 |
1/1✓ Branch 2 taken 320 times.
|
320 | Exception(const std::string& msg) : m_msg(msg) {} |
| 21 | |||
| 22 | /// Needed for rb_raise support in swig | ||
| 23 |
1/1✓ Branch 2 taken 8 times.
|
24 | Exception(const char* msg) : m_msg(msg) {} |
| 24 | |||
| 25 | ✗ | Exception(const Exception&) = default; | |
| 26 | Exception& operator=(const Exception&) = default; | ||
| 27 | ✗ | Exception(Exception&&) = default; | |
| 28 | Exception& operator=(Exception&&) = default; | ||
| 29 | 302 | virtual ~Exception() noexcept override = default; | |
| 30 | |||
| 31 | /// return the message | ||
| 32 | 32 | virtual const std::string& message() const { | |
| 33 | 32 | return m_msg; | |
| 34 | } | ||
| 35 | |||
| 36 | /// return the message | ||
| 37 | 37 | virtual const char* what() const noexcept override { | |
| 38 | 37 | return m_msg.c_str(); | |
| 39 | } | ||
| 40 | |||
| 41 | private: | ||
| 42 | std::string m_msg; | ||
| 43 | }; | ||
| 44 | |||
| 45 | } // namespace openstudio | ||
| 46 | |||
| 47 | #endif // UTILITIES_CORE_EXCEPTION_HPP | ||
| 48 |