00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FIX_EXCEPTIONS_H
00023 #define FIX_EXCEPTIONS_H
00024
00025 #include <string>
00026 #include <stdexcept>
00027 #include "Utility.h"
00028
00029 namespace FIX
00030 {
00031
00033 struct Exception : public std::logic_error
00034 {
00035 Exception( const std::string& t, const std::string& d )
00036 : std::logic_error( d.size() ? t + ": " + d : t ),
00037 type( t ), detail( d )
00038 {}
00039 ~Exception() throw() {}
00040
00041 std::string type;
00042 std::string detail;
00043 };
00044
00046 struct FieldNotFound : public Exception
00047 {
00048 FieldNotFound( int f = 0, const std::string& what = "" )
00049 : Exception( "Field not found", what ),
00050 field( f ) {}
00051 int field;
00052 };
00053
00055 struct FieldConvertError : public Exception
00056 {
00057 FieldConvertError( const std::string& what = "" )
00058 : Exception( "Could not convert field", what ) {}
00059 };
00060
00062 struct MessageParseError : public Exception
00063 {
00064 MessageParseError( const std::string& what = "" )
00065 : Exception( "Could not parse message", what ) {}
00066 };
00067
00069 struct InvalidMessage : public Exception
00070 {
00071 InvalidMessage( const std::string& what = "" )
00072 : Exception( "Invalid message", what ) {}
00073 };
00074
00076 struct ConfigError : public Exception
00077 {
00078 ConfigError( const std::string& what = "" )
00079 : Exception( "Configuration failed", what ) {}
00080 };
00081
00083 struct RuntimeError : public Exception
00084 {
00085 RuntimeError( const std::string& what = "" )
00086 : Exception( "Runtime error", what ) {}
00087 };
00088
00090 struct InvalidTagNumber : public Exception
00091 {
00092 InvalidTagNumber( int f = 0, const std::string& what = "" )
00093 : Exception( "Invalid tag number", what ),
00094 field( f ) {}
00095 int field;
00096 };
00097
00099 struct RequiredTagMissing : public Exception
00100 {
00101 RequiredTagMissing( int f = 0, const std::string& what = "" )
00102 : Exception( "Required tag missing", what ),
00103 field( f ) {}
00104 int field;
00105 };
00106
00108 struct TagNotDefinedForMessage : public Exception
00109 {
00110 TagNotDefinedForMessage( int f = 0, const std::string& what = "" )
00111 : Exception( "Tag not defined for this message type", what ),
00112 field( f ) {}
00113 int field;
00114 };
00115
00117 struct NoTagValue : public Exception
00118 {
00119 NoTagValue( int f = 0, const std::string& what = "" )
00120 : Exception( "Tag specified without a value", what ),
00121 field( f ) {}
00122 int field;
00123 };
00124
00126 struct IncorrectTagValue : public Exception
00127 {
00128 IncorrectTagValue( int f = 0, const std::string& what = "" )
00129 : Exception( "Value is incorrect (out of range) for this tag", what ),
00130 field( f ) {}
00131 int field;
00132 };
00133
00135 struct IncorrectDataFormat : public Exception
00136 {
00137 IncorrectDataFormat( int f = 0, const std::string& what = "" )
00138 : Exception( "Incorrect data format for value", what ),
00139 field( f ) {}
00140 int field;
00141 };
00142
00144 struct IncorrectMessageStructure : public Exception
00145 {
00146 IncorrectMessageStructure( const std::string& what = "" )
00147 : Exception( "Incorrect message structure", what ) {}
00148 };
00149
00151 struct DuplicateFieldNumber : public Exception
00152 {
00153 DuplicateFieldNumber( const std::string& what = "" )
00154 : Exception( "Duplicate field number", what ) {}
00155 };
00156
00158 struct InvalidMessageType : public Exception
00159 {
00160 InvalidMessageType( const std::string& what = "" )
00161 : Exception( "Invalid Message Type", what ) {}
00162 };
00163
00165 struct UnsupportedMessageType : public Exception
00166 {
00167 UnsupportedMessageType( const std::string& what = "" )
00168 : Exception( "Unsupported Message Type", what ) {}
00169 };
00170
00172 struct UnsupportedVersion : public Exception
00173 {
00174 UnsupportedVersion( const std::string& what = "" )
00175 : Exception( "Unsupported Version", what ) {}
00176 };
00177
00179 struct TagOutOfOrder : public Exception
00180 {
00181 TagOutOfOrder( int f = 0, const std::string& what = "" )
00182 : Exception( "Tag specified out of required order", what ),
00183 field( f ) {}
00184 int field;
00185 };
00186
00188 struct RepeatedTag : public Exception
00189 {
00190 RepeatedTag( int f = 0, const std::string& what = "" )
00191 : Exception( "Repeated tag not part of repeating group", what ),
00192 field( f ) {}
00193 int field;
00194 };
00195
00197 struct RepeatingGroupCountMismatch : public Exception
00198 {
00199 RepeatingGroupCountMismatch( int f = 0, const std::string& what = "" )
00200 : Exception( "Repeating group count mismatch", what ),
00201 field( f ) {}
00202 int field;
00203 };
00204
00206 struct DoNotSend : public Exception
00207 {
00208 DoNotSend( const std::string& what = "" )
00209 : Exception( "Do Not Send Message", what ) {}
00210 };
00211
00213 struct RejectLogon : public Exception
00214 {
00215 RejectLogon( const std::string& what = "" )
00216 : Exception( "Rejected Logon Attempt", what ) {}
00217 };
00218
00220 struct SessionNotFound : public Exception
00221 {
00222 SessionNotFound( const std::string& what = "" )
00223 : Exception( "Session Not Found", what ) {}
00224 };
00225
00227 struct IOException : public Exception
00228 {
00229 IOException( const std::string& what = "" )
00230 : Exception( "IO Error", what ) {}
00231 };
00232
00234 struct SocketException : public Exception
00235 {
00236 SocketException()
00237 : Exception( "Socket Error", errorToWhat() ) {}
00238
00239 SocketException( const std::string& what )
00240 : Exception( "Socket Error", what ) {}
00241
00242 std::string errorToWhat()
00243 {
00244 #ifdef _MSC_VER
00245 error = WSAGetLastError();
00246 char buffer[2048];
00247 FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
00248 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00249 buffer, 2048, NULL );
00250 return buffer;
00251 #else
00252 error = errno;
00253 return strerror( error );
00254 #endif
00255 }
00256
00257 int error;
00258 };
00259
00261 struct SocketSendFailed : public SocketException
00262 {
00263 SocketSendFailed() {}
00264 SocketSendFailed( const std::string& what )
00265 : SocketException( what ) {}
00266 };
00267
00269 struct SocketRecvFailed : public SocketException
00270 {
00271 SocketRecvFailed( int size )
00272 : SocketException( size == 0 ? "Connection reset by peer." : size < 0 ? errorToWhat() : "Success." ) {}
00273 SocketRecvFailed( const std::string& what )
00274 : SocketException( what ) {}
00275 };
00276
00278 struct SocketCloseFailed : public SocketException
00279 {
00280 SocketCloseFailed() {}
00281 SocketCloseFailed( const std::string& what )
00282 : SocketException( what ) {}
00283 };
00284
00286 }
00287
00288 #endif //FIX_EXCEPTIONS_H