fix8  version 1.4.0
Open Source C++ FIX Framework
f8exception.hpp
Go to the documentation of this file.
1 //-------------------------------------------------------------------------------------------------
2 /*
3 
4 Fix8 is released under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
5 
6 Fix8 Open Source FIX Engine.
7 Copyright (C) 2010-16 David L. Dight <fix@fix8.org>
8 
9 Fix8 is free software: you can redistribute it and / or modify it under the terms of the
10 GNU Lesser General Public License as published by the Free Software Foundation, either
11 version 3 of the License, or (at your option) any later version.
12 
13 Fix8 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
14 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 You should have received a copy of the GNU Lesser General Public License along with Fix8.
17 If not, see <http://www.gnu.org/licenses/>.
18 
19 THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
20 COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
21 KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO
23 THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
24 YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
25 
26 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT
27 HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED
28 ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
29 CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
30 NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
31 THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH
32 HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
33 
34 */
35 //-------------------------------------------------------------------------------------------------
36 #ifndef FIX8_EXCEPTION_HPP_
37 #define FIX8_EXCEPTION_HPP_
38 
39 //-------------------------------------------------------------------------------------------------
40 #include <string>
41 #include <sstream>
42 #include <exception>
43 
44 //-------------------------------------------------------------------------------------------------
45 namespace FIX8 {
46 
47 //-------------------------------------------------------------------------------------------------
49 class f8Exception : public std::exception
50 {
51  std::string _reason;
53 
54 public:
57  f8Exception(bool force_logoff=false) : _force_logoff(force_logoff) {}
58 
62  f8Exception(const std::string& msg, bool force_logoff=false)
63  : _reason(msg), _force_logoff(force_logoff) {}
64 
68  f8Exception(const char *msg, bool force_logoff=false)
69  : _reason(msg), _force_logoff(force_logoff) {}
70 
76  template<typename T>
77  f8Exception(const std::string& msg, const T& val, bool force_logoff=false)
78  : _reason(msg), _force_logoff(force_logoff) { format(msg, val); }
79 
81  virtual ~f8Exception() throw() {}
82 
85  const char *what() const throw() { return _reason.c_str(); }
86 
89  bool force_logoff() const { return _force_logoff; }
90 
91 protected:
96  template<typename T>
97  void format(const std::string& msg, const T what)
98  {
99  std::ostringstream ostr;
100  ostr << msg << ": " << what;
101  _reason = ostr.str();
102  }
103 
111  template<typename T, typename S>
112  void format(const std::string& msg, const T what, const std::string& msg2, const S what2)
113  {
114  std::ostringstream ostr;
115  ostr << msg << ": " << what << msg2 << ": " << what2;
116  _reason = ostr.str();
117  }
118 };
119 
120 //-------------------------------------------------------------------------------------------------
122 template<typename T>
124 {
125  const T _tagid;
126  InvalidMetadata(T field) : _tagid(field) { format("Invalid Metadata", field); }
127 };
128 
129 //-------------------------------------------------------------------------------------------------
132 {
133  const int _tagid;
134  DuplicateField(unsigned field) : _tagid(field) { format("Duplicate Field", field); }
135 };
136 
137 //-------------------------------------------------------------------------------------------------
139 
140 template<typename T>
142 {
143  InvalidDomainValue(T what) { format("Invalid Domain Value", what); }
144 };
145 
146 //-------------------------------------------------------------------------------------------------
149 {
150  const int _tagid;
151  InvalidField(unsigned field) : _tagid(field) { format("Invalid Field Added", field); }
152 };
153 
154 //-------------------------------------------------------------------------------------------------
157 {
158  const int _tagid;
159  UnknownField(unsigned field) : _tagid(field) { format("Unknown Field Decoded", field); }
160 };
161 
162 //-------------------------------------------------------------------------------------------------
165 {
166  const unsigned _rseqnum, _eseqnum;
167  InvalidMsgSequence(unsigned rseqnum, unsigned eseqnum)
168  : f8Exception(true), _rseqnum(rseqnum), _eseqnum(eseqnum)
169  { format("Invalid Sequence number, received", rseqnum, " expected", eseqnum); }
170 };
171 
172 //-------------------------------------------------------------------------------------------------
175 {
176  const unsigned _rseqnum, _eseqnum;
177  MsgSequenceTooLow(unsigned rseqnum, unsigned eseqnum)
178  : f8Exception(true), _rseqnum(rseqnum), _eseqnum(eseqnum)
179  { format("Message Sequence too low, received", rseqnum, " expected", eseqnum); }
180 };
181 
182 //-------------------------------------------------------------------------------------------------
185 {
186  const unsigned _length;
187  InvalidBodyLength(unsigned length) : _length(length) { format("Invalid BodyLength", length); }
188 };
189 
190 //-------------------------------------------------------------------------------------------------
193 {
194  InvalidMessage(const std::string& str) { format("Invalid FIX Message", str); }
195  InvalidMessage(const std::string& str, const char *str1) { format("Invalid FIX Message", str, " at", str1); }
196 };
197 
198 //-------------------------------------------------------------------------------------------------
201 {
202  IllegalMessage(const std::string& str) { format("Illegal FIX Message", str); }
203  IllegalMessage(const std::string& str, const char *str1) { format("Illegal FIX Message", str, " at", str1); }
204 };
205 
206 //-------------------------------------------------------------------------------------------------
209 {
210  InvalidVersion(const std::string& str) : f8Exception(true) { format("Invalid FIX Version", str); }
211 };
212 
213 //-------------------------------------------------------------------------------------------------
216 {
217  BadSendingTime(const std::string& str) : f8Exception(true) { format("Bad Sending Time", str); }
218 };
219 
220 //-------------------------------------------------------------------------------------------------
223 {
224  BadCompidId(const std::string& str) : f8Exception(true) { format("Invalid CompId", str); }
225 };
226 
227 //-------------------------------------------------------------------------------------------------
230 {
231  const int _tagid;
232  InvalidRepeatingGroup(unsigned field) : _tagid(field) { format("Invalid Repeating Group", field); }
233  InvalidRepeatingGroup(unsigned field, const char *str)
234  : _tagid(field) { format("Invalid Repeating Group", field, " in", str); }
235 };
236 
237 //-------------------------------------------------------------------------------------------------
240 {
241  int _tagid;
242  MissingRepeatingGroupField(unsigned field) : _tagid(field) { format("First Field in a Repeating Group is Mandatory", field); }
243 };
244 
245 //-------------------------------------------------------------------------------------------------
248 {
249  MissingMessageComponent(const char *text) { format("Missing Message Component", text); }
250 };
251 
252 //-------------------------------------------------------------------------------------------------
255 {
256  const int _tagid;
257  MissingMandatoryField(unsigned field) : _tagid(field) { format("Missing Mandatory Field", field); }
258  MissingMandatoryField(const std::string& reason) : _tagid() { format("Missing Mandatory Field", reason); }
259 };
260 
261 //-------------------------------------------------------------------------------------------------
264 {
265  const unsigned int _chkval;
266  BadCheckSum(unsigned int chkval) : _chkval(chkval) { format("Checksum failure", chkval); }
267 };
268 
269 //-------------------------------------------------------------------------------------------------
272 {
273  f8_threadException(const std::string& reason) { format("Thread error", reason); }
274 };
275 
276 //-------------------------------------------------------------------------------------------------
279 {
280  PeerResetConnection(const std::string& reason) { format("Peer reset connection", reason); }
281 };
282 
283 //-------------------------------------------------------------------------------------------------
286 {
287  InvalidConfiguration(const std::string& str) { format("Invalid configuration setting in", str.empty() ? "unknown" : str); }
288 };
289 
290 //-------------------------------------------------------------------------------------------------
293 {
294  ConfigurationError(const std::string& str) { format("Configuration error", str); }
295  ConfigurationError(const std::string& str, const std::string& str1) { format(str, str1); }
296 };
297 
298 //-------------------------------------------------------------------------------------------------
301 {
302  LogfileException(const std::string& str) { format("Error opening logfile", str); }
303 };
304 
305 //-------------------------------------------------------------------------------------------------
308 {
309  XMLError(const std::string& str) { format("XML parsing error", str); }
310 };
311 
312 //-------------------------------------------------------------------------------------------------
313 
314 } // FIX8
315 
316 #endif // _F8_EXCEPTION_HPP_
XMLError(const std::string &str)
A message was received with an invalid sending time.
An outbound message was missing a header or trailer.
Indicates a static metadata lookup failed. With the exception of user defined fields there should nev...
virtual ~f8Exception()
Dtor.
Definition: f8exception.hpp:81
bool force_logoff() const
Definition: f8exception.hpp:89
A field was decoded in a message that has already been decoded.
ConfigurationError(const std::string &str)
std::string _reason
Definition: f8exception.hpp:51
A message was decoded that had a Fix version not configured for this session.
InvalidMessage(const std::string &str, const char *str1)
void format(const std::string &msg, const T what)
Definition: f8exception.hpp:97
An inbound message had an invalid (incorrect) checksum.
f8Exception(const char *msg, bool force_logoff=false)
Definition: f8exception.hpp:68
ConfigurationError(const std::string &str, const std::string &str1)
An invalid field was decoded.
MsgSequenceTooLow(unsigned rseqnum, unsigned eseqnum)
const unsigned int _chkval
A message was read that was in an illegal format.
f8Exception(bool force_logoff=false)
Definition: f8exception.hpp:57
InvalidRepeatingGroup(unsigned field, const char *str)
InvalidRepeatingGroup(unsigned field)
const unsigned _eseqnum
A message was decoded with an invalid message body length.
InvalidBodyLength(unsigned length)
BadSendingTime(const std::string &str)
InvalidField(unsigned field)
For field types with a specified domain (realm), a value was decoded that was not in the domain set/r...
IllegalMessage(const std::string &str, const char *str1)
LogfileException(const std::string &str)
MissingMandatoryField(unsigned field)
Base exception class.
Definition: f8exception.hpp:49
InvalidConfiguration(const std::string &str)
const unsigned _length
An bad or missing configuration parameter.
InvalidVersion(const std::string &str)
A message was received with an out of sequence sequence number.
void format(const std::string &msg, const T what, const std::string &msg2, const S what2)
InvalidMessage(const std::string &str)
A message was received with an invalid sender/target compid id.
IllegalMessage(const std::string &str)
A pthread attribute error occured.
An invalid repeating group was found while attempting to encode a message.
DuplicateField(unsigned field)
An invalid configuration parameter was passed.
PeerResetConnection(const std::string &reason)
An invalid message was requested or decoded.
Field template. There will ONLY be partial template specialisations of this template.
Definition: field.hpp:256
An invalid repeating group field was found while decoding a message (first field is mandatory)...
A connected peer has reset the connection (disconnected).
const unsigned _rseqnum
An invalid field was requested or added.
InvalidMsgSequence(unsigned rseqnum, unsigned eseqnum)
MissingMessageComponent(const char *text)
An invalid configuration parameter was passed.
MissingRepeatingGroupField(unsigned field)
UnknownField(unsigned field)
An outbound message was missing a mandatory field.
const char * what() const
Definition: f8exception.hpp:85
f8_threadException(const std::string &reason)
BadCheckSum(unsigned int chkval)
BadCompidId(const std::string &str)
A message was received with an out of sequence sequence number.
MissingMandatoryField(const std::string &reason)
f8Exception(const std::string &msg, const T &val, bool force_logoff=false)
Definition: f8exception.hpp:77
Could not open a logfile.
f8Exception(const std::string &msg, bool force_logoff=false)
Definition: f8exception.hpp:62