OnixS CME Drop Copy Handler C++ library  5.7.1
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
12 // part of this source code or associated reference material to any other location for further
13 // reproduction or redistribution, and any amendments to this copyright notice, are expressly
14 // 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 "OnixS/CME/DropCopy/Export.h"
24 
25 #include <exception>
26 #include <string>
27 
28 namespace OnixS { namespace CME { namespace DropCopy {
29 
30 /// List of known errors.
31 struct ONIXS_CME_DROP_COPY_EXPORT KnownErrors
32 {
33  /// List of known errors.
34  enum Enum
35  {
36  /// Indicates absence of error.
38 
39  /// Error has generic nature.
41 
42  /// Product is not licensed.
44 
45  /// Handler configuration is invalid.
47 
48  /// FIX message has invalid structure.
49  /// E.g. misses some of required fields.
50  BadMessage
51  };
52 
53  /// Returns constant from its text presentation.
54  static Enum deserialize(const char* value);
55 
56  /// Returns string presentation of value.
57  static const char* toString(Enum value);
58 };
59 
60 /// Error code.
62 
63 /// Error.
64 class ONIXS_CME_DROP_COPY_EXPORT Error : public std::exception
65 {
66 public:
67  /// Initializes instance with just a code.
68  Error(const std::string& source, ErrorCode code);
69 
70  /// Initializes instance with code and description.
71  Error(const std::string& source, ErrorCode code, const std::string& description);
72 
73  /// Initializes as clone of another error.
74  Error(const Error& other);
75 
76  /// Destruction interface.
77  virtual ~Error() throw();
78 
79  /// Code of error.
80  ErrorCode code() const;
81 
82  /// Human readable description of error.
83  const char* description() const;
84 
85  /// Origin of the error.
86  const char* source() const;
87 
88  /// Human readable description of error.
89  virtual const char* what() const throw();
90 
91  /// String presentation of an error.
92  std::string toString() const;
93 
94  /// Appends presentation of an error to the string.
95  void toString(std::string&) const;
96 
97  /// Copies error attributes from another instance.
98  Error& operator=(const Error& other);
99 
100 private:
101  enum Traits
102  {
103  SourceMaxLength = 128,
104  DescriptionMaxLength = 1024
105  };
106 
107  ErrorCode code_;
108  char source_[SourceMaxLength + 1];
109  char description_[DescriptionMaxLength + 1];
110 };
111 
112 inline ErrorCode Error::code() const
113 {
114  return code_;
115 }
116 
117 inline const char* Error::description() const
118 {
119  return description_;
120 }
121 
122 inline const char* Error::source() const
123 {
124  return source_;
125 }
126 
127 inline std::string Error::toString() const
128 {
129  std::string str;
130  toString(str);
131  return str;
132 }
133 
134 }}}
135 
136 namespace std {
137 // Outputs message into standard stream.
138 ONIXS_CME_DROP_COPY_EXPORT std::ostream&
139 operator<<(std::ostream&, const OnixS::CME::DropCopy::Error&);
140 }
ErrorCode code() const
Code of error.
Definition: Error.h:112
List of known errors.
Definition: Error.h:31
const char * source() const
Origin of the error.
Definition: Error.h:122
KnownErrors::Enum ErrorCode
Error code.
Definition: Error.h:61
STL namespace.
Error has generic nature.
Definition: Error.h:40
Handler configuration is invalid.
Definition: Error.h:46
Indicates absence of error.
Definition: Error.h:37
const char * description() const
Human readable description of error.
Definition: Error.h:117
Enum
List of known errors.
Definition: Error.h:34
std::string toString() const
String presentation of an error.
Definition: Error.h:127