~ubuntu-branches/ubuntu/trusty/miro/trusty

« back to all changes in this revision

Viewing changes to portable/libtorrent/include/libtorrent/asio/system_error.hpp

  • Committer: Daniel Hahler
  • Date: 2010-04-13 18:51:35 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: ubuntu-launchpad@thequod.de-20100413185135-xi24v1diqg8w406x
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// system_error.hpp
3
 
// ~~~~~~~~~~~~~~~~
4
 
//
5
 
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6
 
//
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)
9
 
//
10
 
 
11
 
#ifndef ASIO_SYSTEM_ERROR_HPP
12
 
#define ASIO_SYSTEM_ERROR_HPP
13
 
 
14
 
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15
 
# pragma once
16
 
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
 
 
18
 
#include "asio/detail/push_options.hpp"
19
 
 
20
 
#include "asio/detail/push_options.hpp"
21
 
#include <boost/config.hpp>
22
 
#include <boost/scoped_ptr.hpp>
23
 
#include <cerrno>
24
 
#include <exception>
25
 
#include <string>
26
 
#include "asio/detail/pop_options.hpp"
27
 
 
28
 
#include "asio/error_code.hpp"
29
 
 
30
 
namespace asio {
31
 
 
32
 
/// The system_error class is used to represent system conditions that
33
 
/// prevent the library from operating correctly.
34
 
class system_error
35
 
  : public std::exception
36
 
{
37
 
public:
38
 
  /// Construct with an error code.
39
 
  system_error(const error_code& code)
40
 
    : code_(code),
41
 
      context_()
42
 
  {
43
 
  }
44
 
 
45
 
  /// Construct with an error code and context.
46
 
  system_error(const error_code& code, const std::string& context)
47
 
    : code_(code),
48
 
      context_(context)
49
 
  {
50
 
  }
51
 
 
52
 
  /// Copy constructor.
53
 
  system_error(const system_error& other)
54
 
    : std::exception(other),
55
 
      code_(other.code_),
56
 
      context_(other.context_),
57
 
      what_()
58
 
  {
59
 
  }
60
 
 
61
 
  /// Destructor.
62
 
  virtual ~system_error() throw ()
63
 
  {
64
 
  }
65
 
 
66
 
  /// Assignment operator.
67
 
  system_error& operator=(const system_error& e)
68
 
  {
69
 
    context_ = e.context_;
70
 
    code_ = e.code_;
71
 
    what_.reset();
72
 
    return *this;
73
 
  }
74
 
 
75
 
  /// Get a string representation of the exception.
76
 
  virtual const char* what() const throw ()
77
 
  {
78
 
    try
79
 
    {
80
 
      if (!what_)
81
 
      {
82
 
        std::string tmp(context_);
83
 
        if (tmp.length())
84
 
          tmp += ": ";
85
 
        tmp += code_.message();
86
 
        what_.reset(new std::string(tmp));
87
 
      }
88
 
      return what_->c_str();
89
 
    }
90
 
    catch (std::exception&)
91
 
    {
92
 
      return "system_error";
93
 
    }
94
 
  }
95
 
 
96
 
  /// Get the error code associated with the exception.
97
 
  error_code code() const
98
 
  {
99
 
    return code_;
100
 
  }
101
 
 
102
 
private:
103
 
  // The code associated with the error.
104
 
  error_code code_;
105
 
 
106
 
  // The context associated with the error.
107
 
  std::string context_;
108
 
 
109
 
  // The string representation of the error.
110
 
  mutable boost::scoped_ptr<std::string> what_;
111
 
};
112
 
 
113
 
} // namespace asio
114
 
 
115
 
#include "asio/detail/pop_options.hpp"
116
 
 
117
 
#endif // ASIO_SYSTEM_ERROR_HPP