OnixS CME Drop Copy Handler C++ library  5.6.0
API documentation
Error.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
4 // and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable OnixS Software
7 // Services Agreement (the Agreement) and Customer end user license agreements granting
8 // a non-assignable, non-transferable and non-exclusive license to use the software
9 // for it's own data processing purposes under the terms defined in the Agreement.
10 //
11 // Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
12 // of this source code or associated reference material to any other location for further reproduction
13 // or redistribution, and any amendments to this copyright notice, are expressly prohibited.
14 //
15 // Any reproduction or redistribution for sale or hiring of the Software not in accordance with
16 // the terms of the Agreement is a violation of copyright law.
17 //
18 
19 #pragma once
20 
21 #include "OnixS/CME/DropCopy/Export.h"
23 
24 #include <exception>
25 #include <string>
26 
27 namespace OnixS { namespace CME { namespace DropCopy {
28 
29 /// List of known errors.
30 struct ONIXS_CME_DROP_COPY_EXPORT KnownErrors
31 {
32  /// List of known errors.
33  enum Enum
34  {
35  /// Indicates absence of error.
37 
38  /// Error has generic nature.
40 
41  /// Product is not licensed.
43 
44  /// Handler configuration is invalid.
46 
47  /// FIX message has invalid structure.
48  /// E.g. misses some of required fields.
49  BadMessage
50  };
51 
52  /// Returns constant from its text presentation.
53  static Enum deserialize(const char* value);
54 
55  /// Returns string presentation of value.
56  static const char* toString(Enum value);
57 };
58 
59 /// Error code.
61 
62 /// Error.
63 class ONIXS_CME_DROP_COPY_EXPORT Error : public std::exception
64 {
65 public:
66  /// Initializes instance with just a code.
67  Error(const std::string& source, ErrorCode code);
68 
69  /// Initializes instance with code and description.
70  Error(const std::string& source, ErrorCode code, const std::string& description);
71 
72  /// Initializes as clone of another error.
73  Error(const Error& other);
74 
75  /// Destruction interface.
76  virtual ~Error() throw();
77 
78  /// Code of error.
79  ErrorCode code() const;
80 
81  /// Human readable description of error.
82  const char* description() const;
83 
84  /// Origin of the error.
85  const char* source() const;
86 
87  /// Human readable description of error.
88  virtual const char* what() const throw();
89 
90  /// String presentation of an error.
91  std::string toString() const;
92 
93  /// Appends presentation of an error to the string.
94  void toString(std::string&) const;
95 
96  /// Copies error attributes from another instance.
97  Error& operator =(const Error& other);
98 
99 private:
100  enum Traits
101  {
102  SourceMaxLength = 128,
103  DescriptionMaxLength = 1024
104  };
105 
106  ErrorCode code_;
107  char source_[SourceMaxLength + 1];
108  char description_[DescriptionMaxLength + 1];
109 };
110 
111 inline ErrorCode Error::code() const
112 {
113  return code_;
114 }
115 
116 inline const char* Error::description() const
117 {
118  return description_;
119 }
120 
121 inline const char* Error::source() const
122 {
123  return source_;
124 }
125 
126 inline std::string Error::toString() const
127 {
128  std::string str;
129  toString(str);
130  return str;
131 }
132 
133 }}}
134 
135 namespace std {
136 // Outputs message into standard stream.
137 ONIXS_CME_DROP_COPY_EXPORT std::ostream& operator<<(std::ostream&, const OnixS::CME::DropCopy::Error&);
138 }
ErrorCode code() const
Code of error.
Definition: Error.h:111
List of known errors.
Definition: Error.h:30
const char * source() const
Origin of the error.
Definition: Error.h:121
KnownErrors::Enum ErrorCode
Error code.
Definition: Error.h:60
STL namespace.
Error has generic nature.
Definition: Error.h:39
Handler configuration is invalid.
Definition: Error.h:45
Indicates absence of error.
Definition: Error.h:36
const char * description() const
Human readable description of error.
Definition: Error.h:116
Enum
List of known errors.
Definition: Error.h:33
std::string toString() const
String presentation of an error.
Definition: Error.h:126