| 1 | #ifndef BANDIT_ASSERTION_EXCEPTION_H |
| 2 | #define BANDIT_ASSERTION_EXCEPTION_H |
| 3 | |
| 4 | #include <stdexcept> |
| 5 | #include <string> |
| 6 | |
| 7 | namespace bandit { |
| 8 | namespace detail { |
| 9 | struct assertion_exception : public std::runtime_error { |
| 10 | assertion_exception(const std::string& message, |
| 11 | const std::string& filename, const unsigned int linenumber) |
| 12 | : std::runtime_error(message), file_name_(filename), line_number_(linenumber) {} |
| 13 | |
| 14 | assertion_exception(const std::string& message) |
| 15 | : std::runtime_error(message), line_number_(0) {} |
| 16 | |
| 17 | // To make gcc < 4.7 happy. |
| 18 | assertion_exception(const assertion_exception&) = default; |
| 19 | |
| 20 | #ifndef _MSC_VER |
| 21 | assertion_exception(assertion_exception&&) = default; |
| 22 | #else |
| 23 | assertion_exception(assertion_exception&& other) |
| 24 | : std::runtime_error(other), file_name_(), line_number_(other.line_number_) { |
| 25 | std::swap(file_name_, other.file_name_); |
| 26 | } |
| 27 | #endif |
| 28 | |
| 29 | virtual ~assertion_exception() noexcept {} |
| 30 | |
| 31 | const std::string& file_name() const { |
| 32 | return file_name_; |
| 33 | } |
| 34 | |
| 35 | unsigned int line_number() const { |
| 36 | return line_number_; |
| 37 | } |
| 38 | |
| 39 | private: |
| 40 | std::string file_name_; |
| 41 | unsigned int line_number_; |
| 42 | }; |
| 43 | } |
| 44 | } |
| 45 | #endif |
| 46 | |