The system_error class is used to represent system conditions that prevent the library from operating correctly.
| 40 | /// The system_error class is used to represent system conditions that |
| 41 | /// prevent the library from operating correctly. |
| 42 | class system_error |
| 43 | : public std::exception |
| 44 | { |
| 45 | public: |
| 46 | /// Construct with an error code. |
| 47 | system_error(const error_code& ec) |
| 48 | : code_(ec), |
| 49 | context_() |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | /// Construct with an error code and context. |
| 54 | system_error(const error_code& ec, const std::string& context) |
| 55 | : code_(ec), |
| 56 | context_(context) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | /// Copy constructor. |
| 61 | system_error(const system_error& other) |
| 62 | : std::exception(other), |
| 63 | code_(other.code_), |
| 64 | context_(other.context_), |
| 65 | what_() |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | /// Destructor. |
| 70 | virtual ~system_error() throw () |
| 71 | { |
| 72 | } |
| 73 | |
| 74 | /// Assignment operator. |
| 75 | system_error& operator=(const system_error& e) |
| 76 | { |
| 77 | context_ = e.context_; |
| 78 | code_ = e.code_; |
| 79 | what_.reset(); |
| 80 | return *this; |
| 81 | } |
| 82 | |
| 83 | /// Get a string representation of the exception. |
| 84 | virtual const char* what() const throw () |
| 85 | { |
| 86 | #if !defined(ASIO_NO_EXCEPTIONS) |
| 87 | try |
| 88 | #endif // !defined(ASIO_NO_EXCEPTIONS) |
| 89 | { |
| 90 | if (!what_.get()) |
| 91 | { |
| 92 | std::string tmp(context_); |
| 93 | if (tmp.length()) |
| 94 | tmp += ": "; |
| 95 | tmp += code_.message(); |
| 96 | what_.reset(new std::string(tmp)); |
| 97 | } |
| 98 | return what_->c_str(); |
| 99 | } |
no test coverage detected