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 BadSize(unsigned int packet_size
,
108 unsigned int data_buf_size
,
109 unsigned int required_size
);
110 unsigned int packet_size() const { return m_packet_size
; }
111 unsigned int data_buf_size() const { return m_data_buf_size
; }
112 unsigned int required_size() const { return m_required_size
; }
118 /// System error that provides an errno error code.
120 class BXEXPORT ErrnoError
: public Barry::Error
124 BXLOCAL
static std::string
GetMsg(const std::string
&msg
, int err
);
127 ErrnoError(const std::string
&msg
); // for derived classes
130 ErrnoError(const std::string
&msg
, int err
);
132 int error_code() const { return m_errno
; }
138 /// Thrown by the ConfigFile class when encountering a serious system
139 /// error while loading the global config file for a given PIN.
141 class BXEXPORT ConfigFileError
: public Barry::ErrnoError
144 ConfigFileError(const char *msg
) : Barry::ErrnoError(msg
) {}
145 ConfigFileError(const char *msg
, int err
)
146 : Barry::ErrnoError(msg
, err
)
153 /// Thrown by record classes that don't recognize a given packed format code.
154 /// This exception is mostly handled internally, but is published here
155 /// just in case it escapes.
157 class BXEXPORT BadPackedFormat
: public Barry::Error
162 BadPackedFormat(uint8_t format
)
163 : Barry::Error("Bad packed format - internal exception")
167 uint8_t format() const { return m_format
; }
173 /// Thrown by the socket class if a packet command's response indicates
174 /// an error. Some commands may be able to recover inside the library,
175 /// so a special exception is used, that includes the response code.
177 class BXEXPORT BadPacket
: public Barry::Error
182 BadPacket(uint8_t response
, const std::string
&msg
)
184 , m_response(response
)
187 uint8_t response() const { return m_response
; }
193 /// Thrown by the vformat related barrysync library classes.
195 class BXEXPORT ConvertError
: public Barry::Error
198 ConvertError(const std::string
&msg
) : Barry::Error(msg
) {}
204 /// Thrown by the Backup parser class when there is a problem with the
205 /// low level file operation.
207 class BXEXPORT BackupError
: public Barry::Error
210 BackupError(const std::string
&str
) : Error(str
) {}
216 /// Thrown by the Restore builder class when there is a problem with the
217 /// low level file operation.
219 class BXEXPORT RestoreError
: public Barry::Error
222 RestoreError(const std::string
&str
) : Error(str
) {}