OnixS ICE iMpact Multicast Price Feed Handler C++ library  8.18.0
API documentation
Error.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Onix Solutions Limited. All rights reserved.
3  *
4  * This software owned by Onix Solutions Limited and is protected by copyright law
5  * and international copyright treaties.
6  *
7  * Access to and use of the software is governed by the terms of the applicable ONIXS Software
8  * Services Agreement (the Agreement) and Customer end user license agreements granting
9  * a non-assignable, non-transferable and non-exclusive license to use the software
10  * for it's own data processing purposes under the terms defined in the Agreement.
11  *
12  * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13  * of this source code or associated reference material to any other location for further reproduction
14  * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15  *
16  * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17  * the terms of the Agreement is a violation of copyright law.
18  */
19 
20 #pragma once
21 
22 #include "Export.h"
23 #include "Optional.h"
24 #include "Types.h"
25 
26 #include <iosfwd>
27 #include <string>
28 
29 namespace OnixS { namespace ICE { namespace iMpact { namespace MarketData {
30 
31 /// List of known errors.
32 struct ONIXS_ICEMDH_EXPORT KnownErrors
33 {
34  /// \copydoc KnownErrors
35  enum Enum
36  {
37  /// Indicates absence of error.
39 
40  /// Identifiers errors of generic nature.
42 
43  /// Indicates License-related issues like
44  /// there's no license available or license
45  /// has been expired.
47 
48  /// Handler configuration is invalid.
50 
51  /// Network packet received by the Handler is corrupted.
53 
54  /// iMpact message has invalid structure.
56 
57  /// Indicates that market type from subscription
58  /// is not permitted for the user.
60 
61  /// Indicates irrecoverable log replay failure.
63 
64  /// Indicates ICE login failure.
65  LoginFailure
66  };
67 
68  /// Returns string presentation of a value.
69  static const char* toString(Enum value);
70 };
71 
72 /// Error code.
74 
75 /// Error.
76 class ONIXS_ICEMDH_EXPORT Error : public std::exception
77 {
78 public:
79  /// Initializes instance with just a code.
80  Error(const std::string& source, ErrorCode code);
81 
82  /// Initializes instance with code and description.
83  Error(const std::string& source, ErrorCode code, const std::string& description);
84 
85  /// Initializes instance with code, description and feed ID.
86  Error(const std::string& source, ErrorCode code, const std::string& description, FeedId feedId);
87 
88  /// Initializes as clone of another error.
89  Error(const Error& other);
90 
91  /// Destruction interface.
92  virtual ~Error() throw();
93 
94  /// Feed ID (if available).
95  const Optional<FeedId>& feedId() const;
96 
97  /// Code of error.
98  ErrorCode code() const;
99 
100  /// Human readable description of error.
101  const char* description() const;
102 
103  /// Origin of the error.
104  const char* source() const;
105 
106  /// Human readable description of error.
107  virtual const char* what() const throw();
108 
109  /// String presentation of an error.
110  std::string toString() const;
111 
112  /// Appends presentation of an error to the string.
113  void toString(std::string&) const;
114 
115  /// Copies error attributes from another instance.
116  Error& operator=(const Error& other);
117 
118 private:
119  enum Traits
120  {
121  SourceMaxLength = 128,
122  DescriptionMaxLength = 1024
123  };
124 
125  ErrorCode code_;
126  char source_[SourceMaxLength];
127  char description_[DescriptionMaxLength];
128  Optional<FeedId> feedId_;
129 };
130 
131 /// Make it printable to formatted C++ I/O streams.
132 ONIXS_ICEMDH_EXPORT std::ostream& operator<<(std::ostream&, const Error&);
133 
134 inline const Optional<FeedId>& Error::feedId() const
135 {
136  return feedId_;
137 }
138 
139 inline ErrorCode Error::code() const
140 {
141  return code_;
142 }
143 
144 inline const char* Error::description() const
145 {
146  return description_;
147 }
148 
149 inline const char* Error::source() const
150 {
151  return source_;
152 }
153 
154 inline std::string Error::toString() const
155 {
156  std::string str;
157  toString(str);
158  return str;
159 }
160 
161 }}}} // namespace OnixS::ICE::iMpact::MarketData
Indicates irrecoverable log replay failure.
Definition: Error.h:62
const char * source() const
Origin of the error.
Definition: Error.h:149
Identifiers errors of generic nature.
Definition: Error.h:41
const char * description() const
Human readable description of error.
Definition: Error.h:144
const Optional< FeedId > & feedId() const
Feed ID (if available).
Definition: Error.h:134
ErrorCode code() const
Code of error.
Definition: Error.h:139
std::ostream & operator<<(std::ostream &, const Error &)
Make it printable to formatted C++ I/O streams.
Network packet received by the Handler is corrupted.
Definition: Error.h:52
iMpact message has invalid structure.
Definition: Error.h:55
KnownErrors::Enum ErrorCode
Error code.
Definition: Error.h:73
std::string toString() const
String presentation of an error.
Definition: Error.h:154
int FeedId
Alias for market types.
Definition: Types.h:30