3 /// Common exception classes for the Barry library
7 Copyright (C) 2005-2012, 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__
32 /// \addtogroup exceptions
38 /// The base class for any future derived exceptions.
39 /// Can be thrown on any protocol error.
41 class BXEXPORT Error
: public std::runtime_error
44 Error(const std::string
&str
) : std::runtime_error(str
) {}
51 /// A bad or unknown password when talking to the device.
52 /// Can be thrown in the following instances:
54 /// - no password provided and the device requests one
55 /// - device rejected the available password
56 /// - too few remaining tries left... Barry will refuse to keep
57 /// trying passwords if there are fewer than
58 /// BARRY_MIN_PASSWORD_TRIES tries remaining. In this case,
59 /// out_of_tries() will return true.
62 class BXEXPORT BadPassword
: public Barry::Error
64 int m_remaining_tries
;
68 BadPassword(const std::string
&str
, int remaining_tries
,
71 m_remaining_tries(remaining_tries
),
72 m_out_of_tries(out_of_tries
)
74 int remaining_tries() const { return m_remaining_tries
; }
75 bool out_of_tries() const { return m_out_of_tries
; }
81 /// Thrown by the Socket class if it receives a CLOSE message in
82 /// response to an OPEN command. This can mean a number of things:
84 /// - device is password protected, and the wrong password was given
85 /// - device thinks that the socket is already open
87 /// This special exception thrown so the application can try again
88 /// with a fresh Socket::Open() call.
90 class BXEXPORT SocketCloseOnOpen
: public Barry::Error
93 SocketCloseOnOpen(const std::string
&str
) : Barry::Error(str
) {}
99 /// Thrown by the Connector class when unable to find the requested Pin
100 /// If the attached pin is not Valid(), then unable to autodetect device.
101 /// If pin is Valid(), then the specified pin number was not available.
102 /// probe_count is the number of devices found during the probe.
104 class BXEXPORT PinNotFound
: public Barry::Error
110 PinNotFound(Barry::Pin pin
, int probe_count
)
111 : Barry::Error("PIN not found: " + pin
.Str())
113 , m_probe_count(probe_count
)
116 const Barry::Pin
& pin() const { return m_pin
; }
117 int probe_count() const { return m_probe_count
; }
123 /// Thrown by record classes if their data is invalid and cannot be
124 /// uploaded to the Blackberry.
126 class BXEXPORT BadData
: public Barry::Error
129 BadData(const std::string
&str
)
137 /// Unexpected packet size, or not enough data.
139 class BXEXPORT BadSize
: public Barry::Error
141 unsigned int m_packet_size
,
145 BXLOCAL
static std::string
GetMsg(const char *msg
, unsigned int d
, unsigned int r
);
146 BXLOCAL
static std::string
GetMsg(unsigned int p
, unsigned int d
, unsigned int r
);
149 BadSize(const char *msg
, unsigned int data_size
, unsigned int required_size
);
150 BadSize(unsigned int packet_size
,
151 unsigned int data_buf_size
,
152 unsigned int required_size
);
153 unsigned int packet_size() const { return m_packet_size
; }
154 unsigned int data_buf_size() const { return m_data_buf_size
; }
155 unsigned int required_size() const { return m_required_size
; }
161 /// System error that provides an errno error code.
163 class BXEXPORT ErrnoError
: public Barry::Error
167 BXLOCAL
static std::string
GetMsg(const std::string
&msg
, int err
);
170 ErrnoError(const std::string
&msg
); // for derived classes
173 ErrnoError(const std::string
&msg
, int err
);
175 int error_code() const { return m_errno
; }
181 /// Thrown by the ConfigFile class when encountering a serious system
182 /// error while loading the global config file for a given PIN.
184 class BXEXPORT ConfigFileError
: public Barry::ErrnoError
187 ConfigFileError(const char *msg
) : Barry::ErrnoError(msg
) {}
188 ConfigFileError(const char *msg
, int err
)
189 : Barry::ErrnoError(msg
, err
)
196 /// Thrown by record classes that don't recognize a given packed format code.
197 /// This exception is mostly handled internally, but is published here
198 /// just in case it escapes.
200 class BXEXPORT BadPackedFormat
: public Barry::Error
205 BadPackedFormat(uint8_t format
)
206 : Barry::Error("Bad packed format - internal exception")
210 uint8_t format() const { return m_format
; }
216 /// Thrown by the socket class if a packet command's response indicates
217 /// an error. Some commands may be able to recover inside the library,
218 /// so a special exception is used, that includes the response code.
220 class BXEXPORT BadPacket
: public Barry::Error
225 BadPacket(uint8_t response
, const std::string
&msg
)
227 , m_response(response
)
230 uint8_t response() const { return m_response
; }
236 /// Thrown by the vformat related barrysync library classes.
238 class BXEXPORT ConvertError
: public Barry::Error
241 ConvertError(const std::string
&msg
) : Barry::Error(msg
) {}
247 /// Thrown by the Backup parser class when there is a problem with the
248 /// low level file operation.
250 class BXEXPORT BackupError
: public Barry::Error
253 BackupError(const std::string
&str
) : Error(str
) {}
259 /// Thrown by the Restore builder class when there is a problem with the
260 /// low level file operation.
262 class BXEXPORT RestoreError
: public Barry::Error
265 RestoreError(const std::string
&str
) : Error(str
) {}
271 /// Thrown by the Mode::Desktop class when a database command returns
272 /// a non-zero error code. Can happen when writing or clearing a database.
273 /// The packet command and return code are passed along, for examination
274 /// by application code. Note that return code 0x02 usually means
275 /// you're trying to clear or write to a read-only database, like Time Zones.
277 class BXEXPORT ReturnCodeError
: public Barry::Error
279 unsigned int m_command
, m_return_code
;
282 ReturnCodeError(const std::string
&str
, unsigned int command
,
283 unsigned int return_code
)
286 , m_return_code(return_code
)
290 unsigned int command() const { return m_command
; }
291 unsigned int return_code() const { return m_return_code
; }