error.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __BARRY_ERROR_H__
00023 #define __BARRY_ERROR_H__
00024
00025 #include "dll.h"
00026 #include <stdexcept>
00027 #include <stdint.h>
00028
00029 namespace Barry {
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class BXEXPORT Error : public std::runtime_error
00041 {
00042 public:
00043 Error(const std::string &str) : std::runtime_error(str) {}
00044 };
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 class BXEXPORT BadPassword : public Barry::Error
00062 {
00063 int m_remaining_tries;
00064 bool m_out_of_tries;
00065
00066 public:
00067 BadPassword(const std::string &str, int remaining_tries,
00068 bool out_of_tries)
00069 : Barry::Error(str),
00070 m_remaining_tries(remaining_tries),
00071 m_out_of_tries(out_of_tries)
00072 {}
00073 int remaining_tries() const { return m_remaining_tries; }
00074 bool out_of_tries() const { return m_out_of_tries; }
00075 };
00076
00077
00078
00079
00080
00081
00082
00083 class BXEXPORT BadData : public Barry::Error
00084 {
00085 public:
00086 BadData(const std::string &str)
00087 : Barry::Error(str)
00088 {}
00089 };
00090
00091
00092
00093
00094
00095
00096 class BXEXPORT BadSize : public Barry::Error
00097 {
00098 unsigned int m_packet_size,
00099 m_data_buf_size,
00100 m_required_size;
00101
00102 BXLOCAL static std::string GetMsg(const char *msg, unsigned int d, unsigned int r);
00103 BXLOCAL static std::string GetMsg(unsigned int p, unsigned int d, unsigned int r);
00104
00105 public:
00106 BadSize(const char *msg, unsigned int data_size, unsigned int required_size)
00107 : Barry::Error(GetMsg(msg, data_size, required_size))
00108 , m_packet_size(0)
00109 , m_data_buf_size(data_size)
00110 , m_required_size(required_size)
00111 {}
00112 BadSize(unsigned int packet_size,
00113 unsigned int data_buf_size,
00114 unsigned int required_size)
00115 : Barry::Error(GetMsg(packet_size, data_buf_size, required_size))
00116 , m_packet_size(packet_size)
00117 , m_data_buf_size(data_buf_size)
00118 , m_required_size(required_size)
00119 {}
00120 unsigned int packet_size() const { return m_packet_size; }
00121 unsigned int data_buf_size() const { return m_data_buf_size; }
00122 unsigned int required_size() const { return m_required_size; }
00123 };
00124
00125
00126
00127
00128
00129
00130 class BXEXPORT ErrnoError : public Barry::Error
00131 {
00132 int m_errno;
00133
00134 static std::string GetMsg(const std::string &msg, int err);
00135
00136 protected:
00137 ErrnoError(const std::string &msg)
00138 : Barry::Error(msg)
00139 , m_errno(0)
00140 {}
00141
00142 public:
00143 ErrnoError(const std::string &msg, int err)
00144 : Barry::Error(GetMsg(msg, err))
00145 , m_errno(err)
00146 {}
00147
00148 int error_code() const { return m_errno; }
00149 };
00150
00151
00152
00153
00154
00155
00156
00157 class ConfigFileError : public Barry::ErrnoError
00158 {
00159 public:
00160 ConfigFileError(const char *msg) : Barry::ErrnoError(msg) {}
00161 ConfigFileError(const char *msg, int err)
00162 : Barry::ErrnoError(msg, err)
00163 {}
00164 };
00165
00166
00167
00168
00169
00170
00171
00172
00173 class BXEXPORT BadPackedFormat : public Barry::Error
00174 {
00175 uint8_t m_format;
00176
00177 public:
00178 BadPackedFormat(uint8_t format)
00179 : Barry::Error("Bad packed format - internal exception")
00180 , m_format(format)
00181 {}
00182
00183 uint8_t format() const { return m_format; }
00184 };
00185
00186
00187
00188
00189
00190
00191
00192
00193 class BXEXPORT BadPacket : public Barry::Error
00194 {
00195 uint8_t m_response;
00196
00197 public:
00198 BadPacket(uint8_t response, const std::string &msg)
00199 : Barry::Error(msg)
00200 , m_response(response)
00201 {}
00202
00203 uint8_t response() const { return m_response; }
00204 };
00205
00206
00207
00208 }
00209
00210 #endif
00211