5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11
#ifndef ASIO_SYSTEM_ERROR_HPP
12
#define ASIO_SYSTEM_ERROR_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
20
#include "asio/detail/push_options.hpp"
21
#include <boost/config.hpp>
22
#include <boost/scoped_ptr.hpp>
26
#include "asio/detail/pop_options.hpp"
28
#include "asio/error_code.hpp"
32
/// The system_error class is used to represent system conditions that
33
/// prevent the library from operating correctly.
35
: public std::exception
38
/// Construct with an error code.
39
system_error(const error_code& code)
45
/// Construct with an error code and context.
46
system_error(const error_code& code, const std::string& context)
53
system_error(const system_error& other)
54
: std::exception(other),
56
context_(other.context_),
62
virtual ~system_error() throw ()
66
/// Assignment operator.
67
system_error& operator=(const system_error& e)
69
context_ = e.context_;
75
/// Get a string representation of the exception.
76
virtual const char* what() const throw ()
82
std::string tmp(context_);
85
tmp += code_.message();
86
what_.reset(new std::string(tmp));
88
return what_->c_str();
90
catch (std::exception&)
92
return "system_error";
96
/// Get the error code associated with the exception.
97
error_code code() const
103
// The code associated with the error.
106
// The context associated with the error.
107
std::string context_;
109
// The string representation of the error.
110
mutable boost::scoped_ptr<std::string> what_;
115
#include "asio/detail/pop_options.hpp"
117
#endif // ASIO_SYSTEM_ERROR_HPP