OnixS ICE iMpact Multicast Price Feed Handler C++ library  8.17.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(
81  const std::string& source
82  , ErrorCode code
83  );
84 
85  /// Initializes instance with code and description.
86  Error(
87  const std::string& source
88  , ErrorCode code
89  , const std::string& description
90  );
91 
92  /// Initializes instance with code, description and feed ID.
93  Error(
94  const std::string& source
95  , ErrorCode code
96  , const std::string& description
97  , FeedId feedId
98  );
99 
100  /// Initializes as clone of another error.
101  Error(const Error& other);
102 
103  /// Destruction interface.
104  virtual ~Error() throw();
105 
106  /// Feed ID (if available).
107  const Optional<FeedId>& feedId() const;
108 
109  /// Code of error.
110  ErrorCode code() const;
111 
112  /// Human readable description of error.
113  const char* description() const;
114 
115  /// Origin of the error.
116  const char* source() const;
117 
118  /// Human readable description of error.
119  virtual const char* what() const throw();
120 
121  /// String presentation of an error.
122  std::string toString() const;
123 
124  /// Appends presentation of an error to the string.
125  void toString(std::string&) const;
126 
127  /// Copies error attributes from another instance.
128  Error& operator=(const Error& other);
129 
130 private:
131  enum Traits
132  {
133  SourceMaxLength = 128
134  , DescriptionMaxLength = 1024
135  };
136 
137  ErrorCode code_;
138  char source_[SourceMaxLength];
139  char description_[DescriptionMaxLength];
140  Optional<FeedId> feedId_;
141 };
142 
143 /// Make it printable to formatted C++ I/O streams.
144 ONIXS_ICEMDH_EXPORT std::ostream& operator<<(std::ostream&, const Error&);
145 
146 inline const Optional<FeedId>& Error::feedId() const
147 {
148  return feedId_;
149 }
150 
151 inline ErrorCode Error::code() const
152 {
153  return code_;
154 }
155 
156 inline const char* Error::description() const
157 {
158  return description_;
159 }
160 
161 inline const char* Error::source() const
162 {
163  return source_;
164 }
165 
166 inline std::string Error::toString() const
167 {
168  std::string str;
169  toString(str);
170  return str;
171 }
172 
173 }}}} // namespace MarketData, iMpact, ICE, OnixS
Indicates irrecoverable log replay failure.
Definition: Error.h:62
const char * source() const
Origin of the error.
Definition: Error.h:161
Identifiers errors of generic nature.
Definition: Error.h:41
const char * description() const
Human readable description of error.
Definition: Error.h:156
const Optional< FeedId > & feedId() const
Feed ID (if available).
Definition: Error.h:146
ErrorCode code() const
Code of error.
Definition: Error.h:151
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:166
int FeedId
Alias for market types.
Definition: Types.h:30