3 /// Common exception classes for the Barry library
7 Copyright (C) 2005-2010, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_ERROR_H__
23 #define __BARRY_ERROR_H__
31 /// \addtogroup exceptions
37 /// The base class for any future derived exceptions.
38 /// Can be thrown on any protocol error.
40 class BXEXPORT Error
: public std::runtime_error
43 Error(const std::string
&str
) : std::runtime_error(str
) {}
50 /// A bad or unknown password when talking to the device.
51 /// Can be thrown in the following instances:
53 /// - no password provided and the device requests one
54 /// - device rejected the available password
55 /// - too few remaining tries left... Barry will refuse to keep
56 /// trying passwords if there are fewer than
57 /// BARRY_MIN_PASSWORD_TRIES tries remaining. In this case,
58 /// out_of_tries() will return true.
61 class BXEXPORT BadPassword
: public Barry::Error
63 int m_remaining_tries
;
67 BadPassword(const std::string
&str
, int remaining_tries
,
70 m_remaining_tries(remaining_tries
),
71 m_out_of_tries(out_of_tries
)
73 int remaining_tries() const { return m_remaining_tries
; }
74 bool out_of_tries() const { return m_out_of_tries
; }
80 /// Thrown by record classes if their data is invalid and cannot be
81 /// uploaded to the Blackberry.
83 class BXEXPORT BadData
: public Barry::Error
86 BadData(const std::string
&str
)
94 /// Unexpected packet size, or not enough data.
96 class BXEXPORT BadSize
: public Barry::Error
98 unsigned int m_packet_size
,
102 BXLOCAL
static std::string
GetMsg(const char *msg
, unsigned int d
, unsigned int r
);
103 BXLOCAL
static std::string
GetMsg(unsigned int p
, unsigned int d
, unsigned int r
);
106 BadSize(const char *msg
, unsigned int data_size
, unsigned int required_size
)
107 : Barry::Error(GetMsg(msg
, data_size
, required_size
))
109 , m_data_buf_size(data_size
)
110 , m_required_size(required_size
)
112 BadSize(unsigned int packet_size
,
113 unsigned int data_buf_size
,
114 unsigned int required_size
)
115 : Barry::Error(GetMsg(packet_size
, data_buf_size
, required_size
))
116 , m_packet_size(packet_size
)
117 , m_data_buf_size(data_buf_size
)
118 , m_required_size(required_size
)
120 unsigned int packet_size() const { return m_packet_size
; }
121 unsigned int data_buf_size() const { return m_data_buf_size
; }
122 unsigned int required_size() const { return m_required_size
; }
128 /// System error that provides an errno error code.
130 class BXEXPORT ErrnoError
: public Barry::Error
134 static std::string
GetMsg(const std::string
&msg
, int err
);
137 ErrnoError(const std::string
&msg
) // for derived classes
143 ErrnoError(const std::string
&msg
, int err
)
144 : Barry::Error(GetMsg(msg
, err
))
148 int error_code() const { return m_errno
; }
154 /// Thrown by the ConfigFile class when encountering a serious system
155 /// error while loading the global config file for a given PIN.
157 class ConfigFileError
: public Barry::ErrnoError
160 ConfigFileError(const char *msg
) : Barry::ErrnoError(msg
) {}
161 ConfigFileError(const char *msg
, int err
)
162 : Barry::ErrnoError(msg
, err
)
169 /// Thrown by record classes that don't recognize a given packed format code.
170 /// This exception is mostly handled internally, but is published here
171 /// just in case it escapes.
173 class BXEXPORT BadPackedFormat
: public Barry::Error
178 BadPackedFormat(uint8_t format
)
179 : Barry::Error("Bad packed format - internal exception")
183 uint8_t format() const { return m_format
; }
189 /// Thrown by the socket class if a packet command's response indicates
190 /// an error. Some commands may be able to recover inside the library,
191 /// so a special exception is used, that includes the response code.
193 class BXEXPORT BadPacket
: public Barry::Error
198 BadPacket(uint8_t response
, const std::string
&msg
)
200 , m_response(response
)
203 uint8_t response() const { return m_response
; }
209 /// Thrown by the vformat related barrysync library classes.
211 class ConvertError
: public Barry::Error
214 ConvertError(const std::string
&msg
) : Barry::Error(msg
) {}