~ubuntu-branches/debian/experimental/libtorrent/experimental

« back to all changes in this revision

Viewing changes to src/torrent/exceptions.h

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas
  • Date: 2007-03-31 10:31:05 UTC
  • mto: (4.1.4 gutsy) (6.2.1 squeeze) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20070331103105-jzpp1rml6ud0ff75
Tags: upstream-0.11.4
ImportĀ upstreamĀ versionĀ 0.11.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
#include <exception>
41
41
#include <string>
 
42
#include <torrent/common.h>
42
43
 
43
44
namespace torrent {
44
45
 
45
 
// all exceptions inherit from runtime_error to make catching everything
46
 
// at the root easier.
47
 
 
48
 
class base_error : public std::exception {
 
46
// All exceptions inherit from std::exception to make catching
 
47
// everything libtorrent related at the root easier.
 
48
class LIBTORRENT_EXPORT base_error : public std::exception {
49
49
public:
50
 
  base_error(const std::string& msg) : m_msg(msg) {}
51
50
  virtual ~base_error() throw() {}
52
 
 
53
 
  virtual const char* what() const throw() { return m_msg.c_str(); }
54
 
 
55
 
  void set(const std::string& msg) { m_msg = msg; }
56
 
 
57
 
private:
58
 
  std::string m_msg;
59
 
};
60
 
 
61
 
class program_error : public base_error {
62
 
public:
63
 
  program_error(const std::string& msg) : base_error(msg) {}
64
 
};
65
 
 
66
 
// The library or application did some borking it shouldn't have, bug tracking time!
67
 
class internal_error : public program_error {
68
 
public:
 
51
};
 
52
 
 
53
// The library or application did some borking it shouldn't have, bug
 
54
// tracking time!
 
55
class LIBTORRENT_EXPORT internal_error : public base_error {
 
56
public:
 
57
  internal_error(const char* msg);
69
58
  internal_error(const std::string& msg);
70
 
};
71
 
 
72
 
class client_error : public program_error {
73
 
public:
74
 
  client_error(const std::string& msg);
 
59
  virtual ~internal_error() throw() {}
 
60
 
 
61
  virtual const char* what() const throw() { return m_msg.c_str(); }
 
62
 
 
63
private:
 
64
  std::string m_msg;
75
65
};
76
66
 
77
67
// For some reason we couldn't talk with a protocol/tracker, migth be a
78
68
// library bug, connection problem or bad input.
79
 
class network_error : public base_error {
80
 
public:
81
 
  network_error(const std::string& msg) : base_error(msg) {}
82
 
};
83
 
 
84
 
class communication_error : public network_error {
85
 
public:
86
 
  communication_error(const std::string& msg) : network_error(msg) {}
87
 
};
88
 
 
89
 
class connection_error : public network_error {
90
 
public:
91
 
  connection_error(const std::string& msg) : network_error(msg) {}
92
 
};
93
 
 
94
 
class close_connection : public network_error {
95
 
public:
96
 
  close_connection() : network_error("") {}
97
 
 
98
 
  close_connection(const std::string& msg) : network_error(msg) {}
99
 
};
100
 
 
101
 
class blocked_connection : public network_error {
102
 
public:
103
 
  blocked_connection() : network_error("") {}
 
69
class LIBTORRENT_EXPORT network_error : public base_error {
 
70
public:
 
71
  virtual ~network_error() throw() {}
 
72
};
 
73
 
 
74
class LIBTORRENT_EXPORT communication_error : public network_error {
 
75
public:
 
76
  communication_error(const char* msg);
 
77
  communication_error(const std::string& msg);
 
78
  virtual ~communication_error() throw() {}
 
79
 
 
80
  virtual const char* what() const throw() { return m_msg.c_str(); }
 
81
 
 
82
private:
 
83
  std::string m_msg;
 
84
};
 
85
 
 
86
class LIBTORRENT_EXPORT connection_error : public network_error {
 
87
public:
 
88
  connection_error(int err) : m_errno(err) {}
 
89
  virtual ~connection_error() throw() {}
 
90
 
 
91
  virtual const char* what() const throw();
 
92
 
 
93
private:
 
94
  int m_errno;
 
95
};
 
96
 
 
97
class LIBTORRENT_EXPORT close_connection : public network_error {
 
98
public:
 
99
  virtual ~close_connection() throw() {}
 
100
};
 
101
 
 
102
class LIBTORRENT_EXPORT blocked_connection : public network_error {
 
103
public:
 
104
  virtual ~blocked_connection() throw() {}
104
105
};
105
106
 
106
107
// Stuff like bad torrent file, disk space and permissions.
107
 
class local_error : public base_error {
 
108
class LIBTORRENT_EXPORT local_error : public base_error {
108
109
public:
109
 
  local_error(const std::string& msg) : base_error(msg) {}
 
110
  virtual ~local_error() throw() {}
110
111
};
111
112
 
112
 
class storage_error : public local_error {
 
113
class LIBTORRENT_EXPORT storage_error : public local_error {
113
114
public:
 
115
  storage_error(const char* msg);
114
116
  storage_error(const std::string& msg);
115
 
};
116
 
 
117
 
class input_error : public local_error {
118
 
public:
119
 
  input_error(const std::string& msg) : local_error(msg) {}
120
 
};
121
 
 
122
 
class bencode_error : public input_error {
123
 
public:
 
117
  virtual ~storage_error() throw() {}
 
118
 
 
119
  virtual const char* what() const throw() { return m_msg.c_str(); }
 
120
 
 
121
private:
 
122
  std::string m_msg;
 
123
};
 
124
 
 
125
class LIBTORRENT_EXPORT resource_error : public local_error {
 
126
public:
 
127
  resource_error(const char* msg);
 
128
  resource_error(const std::string& msg);
 
129
  virtual ~resource_error() throw() {}
 
130
 
 
131
  virtual const char* what() const throw() { return m_msg.c_str(); }
 
132
 
 
133
private:
 
134
  std::string m_msg;
 
135
};
 
136
 
 
137
class LIBTORRENT_EXPORT input_error : public local_error {
 
138
public:
 
139
  input_error(const char* msg);
 
140
  input_error(const std::string& msg);
 
141
  virtual ~input_error() throw() {}
 
142
 
 
143
  virtual const char* what() const throw() { return m_msg.c_str(); }
 
144
 
 
145
private:
 
146
  std::string m_msg;
 
147
};
 
148
 
 
149
class LIBTORRENT_EXPORT bencode_error : public input_error {
 
150
public:
 
151
  bencode_error(const char* msg) : input_error(msg) {}
124
152
  bencode_error(const std::string& msg) : input_error(msg) {}
 
153
 
 
154
  virtual ~bencode_error() throw() {}
125
155
};
126
156
 
127
 
} // namespace torrent
 
157
}
128
158
 
129
 
#endif // LIBTORRENT_EXCEPTIONS_H
 
159
#endif