40
40
#include <exception>
42
#include <torrent/common.h>
43
44
namespace torrent {
45
// all exceptions inherit from runtime_error to make catching everything
46
// at the root easier.
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 {
50
base_error(const std::string& msg) : m_msg(msg) {}
51
50
virtual ~base_error() throw() {}
53
virtual const char* what() const throw() { return m_msg.c_str(); }
55
void set(const std::string& msg) { m_msg = msg; }
61
class program_error : public base_error {
63
program_error(const std::string& msg) : base_error(msg) {}
66
// The library or application did some borking it shouldn't have, bug tracking time!
67
class internal_error : public program_error {
53
// The library or application did some borking it shouldn't have, bug
55
class LIBTORRENT_EXPORT internal_error : public base_error {
57
internal_error(const char* msg);
69
58
internal_error(const std::string& msg);
72
class client_error : public program_error {
74
client_error(const std::string& msg);
59
virtual ~internal_error() throw() {}
61
virtual const char* what() const throw() { return m_msg.c_str(); }
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 {
81
network_error(const std::string& msg) : base_error(msg) {}
84
class communication_error : public network_error {
86
communication_error(const std::string& msg) : network_error(msg) {}
89
class connection_error : public network_error {
91
connection_error(const std::string& msg) : network_error(msg) {}
94
class close_connection : public network_error {
96
close_connection() : network_error("") {}
98
close_connection(const std::string& msg) : network_error(msg) {}
101
class blocked_connection : public network_error {
103
blocked_connection() : network_error("") {}
69
class LIBTORRENT_EXPORT network_error : public base_error {
71
virtual ~network_error() throw() {}
74
class LIBTORRENT_EXPORT communication_error : public network_error {
76
communication_error(const char* msg);
77
communication_error(const std::string& msg);
78
virtual ~communication_error() throw() {}
80
virtual const char* what() const throw() { return m_msg.c_str(); }
86
class LIBTORRENT_EXPORT connection_error : public network_error {
88
connection_error(int err) : m_errno(err) {}
89
virtual ~connection_error() throw() {}
91
virtual const char* what() const throw();
97
class LIBTORRENT_EXPORT close_connection : public network_error {
99
virtual ~close_connection() throw() {}
102
class LIBTORRENT_EXPORT blocked_connection : public network_error {
104
virtual ~blocked_connection() throw() {}
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 {
109
local_error(const std::string& msg) : base_error(msg) {}
110
virtual ~local_error() throw() {}
112
class storage_error : public local_error {
113
class LIBTORRENT_EXPORT storage_error : public local_error {
115
storage_error(const char* msg);
114
116
storage_error(const std::string& msg);
117
class input_error : public local_error {
119
input_error(const std::string& msg) : local_error(msg) {}
122
class bencode_error : public input_error {
117
virtual ~storage_error() throw() {}
119
virtual const char* what() const throw() { return m_msg.c_str(); }
125
class LIBTORRENT_EXPORT resource_error : public local_error {
127
resource_error(const char* msg);
128
resource_error(const std::string& msg);
129
virtual ~resource_error() throw() {}
131
virtual const char* what() const throw() { return m_msg.c_str(); }
137
class LIBTORRENT_EXPORT input_error : public local_error {
139
input_error(const char* msg);
140
input_error(const std::string& msg);
141
virtual ~input_error() throw() {}
143
virtual const char* what() const throw() { return m_msg.c_str(); }
149
class LIBTORRENT_EXPORT bencode_error : public input_error {
151
bencode_error(const char* msg) : input_error(msg) {}
124
152
bencode_error(const std::string& msg) : input_error(msg) {}
154
virtual ~bencode_error() throw() {}
127
} // namespace torrent
129
#endif // LIBTORRENT_EXCEPTIONS_H