QuickFIX: /home/omiller/Development/autobuild/quickfix/src/C++/Exceptions.h Source File

Index Source Files Annotated Class List Alphabetical Class List Class Hierarchy Graphical Class Hierarchy

# Exceptions.h

Go to the documentation of this file.

    00001 /* -*- C++ -*- */
    00002
    00003 /****************************************************************************
    00004 ** Copyright (c) quickfixengine.org  All rights reserved.
    00005 **
    00006 ** This file is part of the QuickFIX FIX Engine
    00007 **
    00008 ** This file may be distributed under the terms of the quickfixengine.org
    00009 ** license as defined by quickfixengine.org and appearing in the file
    00010 ** LICENSE included in the packaging of this file.
    00011 **
    00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00014 **
    00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
    00016 **
    00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
    00018 ** not clear to you.
    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 DataDictionaryNotFound : public Exception
    00047 {
    00048   DataDictionaryNotFound( const std::string& v, const std::string& what = "" )
    00049     : Exception( "Could not find data dictionary", what ),
    00050                  version( v ) {}
    00051   ~DataDictionaryNotFound() throw() {}
    00052
    00053   std::string version;
    00054 };
    00055
    00057 struct FieldNotFound : public Exception
    00058 {
    00059   FieldNotFound( int f = 0, const std::string& what = "" )
    00060     : Exception( "Field not found", what ),
    00061                  field( f ) {}
    00062   int field;
    00063 };
    00064
    00066 struct FieldConvertError : public Exception
    00067 {
    00068   FieldConvertError( const std::string& what = "" )
    00069     : Exception( "Could not convert field", what ) {}
    00070 };
    00071
    00073 struct MessageParseError : public Exception
    00074 {
    00075   MessageParseError( const std::string& what = "" )
    00076     : Exception( "Could not parse message", what ) {}
    00077 };
    00078
    00080 struct InvalidMessage : public Exception
    00081 {
    00082   InvalidMessage( const std::string& what = "" )
    00083     : Exception( "Invalid message", what ) {}
    00084 };
    00085
    00087 struct ConfigError : public Exception
    00088 {
    00089   ConfigError( const std::string& what = "" )
    00090     : Exception( "Configuration failed", what ) {}
    00091 };
    00092
    00094 struct RuntimeError : public Exception
    00095 {
    00096   RuntimeError( const std::string& what = "" )
    00097     : Exception( "Runtime error", what ) {}
    00098 };
    00099
    00101 struct InvalidTagNumber : public Exception
    00102 {
    00103   InvalidTagNumber( int f = 0, const std::string& what = "" )
    00104     : Exception( "Invalid tag number", what ),
    00105                  field( f ) {}
    00106   int field;
    00107 };
    00108
    00110 struct RequiredTagMissing : public Exception
    00111 {
    00112   RequiredTagMissing( int f = 0, const std::string& what = "" )
    00113     : Exception( "Required tag missing", what ),
    00114                  field( f ) {}
    00115   int field;
    00116 };
    00117
    00119 struct TagNotDefinedForMessage : public Exception
    00120 {
    00121   TagNotDefinedForMessage( int f = 0, const std::string& what = "" )
    00122     : Exception( "Tag not defined for this message type", what ),
    00123                  field( f ) {}
    00124   int field;
    00125 };
    00126
    00128 struct NoTagValue : public Exception
    00129 {
    00130   NoTagValue( int f = 0, const std::string& what = "" )
    00131     : Exception( "Tag specified without a value", what ),
    00132                  field( f ) {}
    00133   int field;
    00134 };
    00135
    00137 struct IncorrectTagValue : public Exception
    00138 {
    00139   IncorrectTagValue( int f = 0, const std::string& what = "" )
    00140     : Exception( "Value is incorrect (out of range) for this tag", what ),
    00141                  field( f ) {}
    00142   int field;
    00143 };
    00144
    00146 struct IncorrectDataFormat : public Exception
    00147 {
    00148   IncorrectDataFormat( int f = 0, const std::string& what = "" )
    00149     : Exception( "Incorrect data format for value", what ),
    00150                  field( f ) {}
    00151   int field;
    00152 };
    00153
    00155 struct IncorrectMessageStructure : public Exception
    00156 {
    00157   IncorrectMessageStructure( const std::string& what = "" )
    00158     : Exception( "Incorrect message structure", what ) {}
    00159 };
    00160
    00162 struct DuplicateFieldNumber : public Exception
    00163 {
    00164   DuplicateFieldNumber( const std::string& what = "" )
    00165     : Exception( "Duplicate field number", what ) {}
    00166 };
    00167
    00169 struct InvalidMessageType : public Exception
    00170 {
    00171   InvalidMessageType( const std::string& what = "" )
    00172     : Exception( "Invalid Message Type", what ) {}
    00173 };
    00174
    00176 struct UnsupportedMessageType : public Exception
    00177 {
    00178   UnsupportedMessageType( const std::string& what = "" )
    00179     : Exception( "Unsupported Message Type", what ) {}
    00180 };
    00181
    00183 struct UnsupportedVersion : public Exception
    00184 {
    00185   UnsupportedVersion( const std::string& what = "" )
    00186     : Exception( "Unsupported Version", what ) {}
    00187 };
    00188
    00190 struct TagOutOfOrder : public Exception
    00191 {
    00192   TagOutOfOrder( int f = 0, const std::string& what = "" )
    00193     : Exception( "Tag specified out of required order", what ),
    00194                  field( f ) {}
    00195   int field;
    00196 };
    00197
    00199 struct RepeatedTag : public Exception
    00200 {
    00201   RepeatedTag( int f = 0, const std::string& what = "" )
    00202     : Exception( "Repeated tag not part of repeating group", what ),
    00203                  field( f ) {}
    00204   int field;
    00205 };
    00206
    00208 struct RepeatingGroupCountMismatch : public Exception
    00209 {
    00210   RepeatingGroupCountMismatch( int f = 0, const std::string& what = "" )
    00211     : Exception( "Repeating group count mismatch", what ),
    00212                  field( f ) {}
    00213   int field;
    00214 };
    00215
    00217 struct DoNotSend : public Exception
    00218 {
    00219   DoNotSend( const std::string& what = "" )
    00220     : Exception( "Do Not Send Message", what ) {}
    00221 };
    00222
    00224 struct RejectLogon : public Exception
    00225 {
    00226   RejectLogon( const std::string& what = "" )
    00227     : Exception( "Rejected Logon Attempt", what ) {}
    00228 };
    00229
    00231 struct SessionNotFound : public Exception
    00232 {
    00233   SessionNotFound( const std::string& what = "" )
    00234     : Exception( "Session Not Found", what ) {}
    00235 };
    00236
    00238 struct IOException : public Exception
    00239 {
    00240   IOException( const std::string& what = "" )
    00241     : Exception( "IO Error", what ) {}
    00242 };
    00243
    00245 struct SocketException : public Exception
    00246 {
    00247   SocketException()
    00248     : Exception( "Socket Error", errorToWhat() ) {}
    00249
    00250   SocketException( const std::string& what )
    00251     : Exception( "Socket Error", what ) {}
    00252
    00253   std::string errorToWhat()
    00254   {
    00255 #ifdef _MSC_VER
    00256     error = WSAGetLastError();
    00257     char buffer[2048];
    00258     FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, error,
    00259                    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    00260                    buffer, 2048, NULL );
    00261     return buffer;
    00262 #else
    00263     error = errno;
    00264     return strerror( error );
    00265 #endif
    00266   }
    00267
    00268   int error;
    00269 };
    00270
    00272 struct SocketSendFailed : public SocketException
    00273 {
    00274   SocketSendFailed() {}
    00275   SocketSendFailed( const std::string& what )
    00276     : SocketException( what ) {}
    00277 };
    00278
    00280 struct SocketRecvFailed : public SocketException
    00281 {
    00282   SocketRecvFailed( int size )
    00283     : SocketException( size == 0 ? "Connection reset by peer." : size < 0 ? errorToWhat() : "Success." ) {}
    00284   SocketRecvFailed( const std::string& what )
    00285     : SocketException( what ) {}
    00286 };
    00287
    00289 struct SocketCloseFailed : public SocketException
    00290 {
    00291   SocketCloseFailed() {}
    00292   SocketCloseFailed( const std::string& what )
    00293     : SocketException( what ) {}
    00294 };
    00295
    00297 }
    00298
    00299 #endif //FIX_EXCEPTIONS_H