OnixS BME SENAF Handler C++ library  2.2.0
API documentation
Error.h
Go to the documentation of this file.
1 /*
2  * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3  *
4  * This software owned by Onix Solutions Limited [OnixS] 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 <OnixS/Senaf/MarketData/Export.h>
23 
24 #include <iosfwd>
25 #include <string>
26 
27 namespace OnixS { namespace Senaf { namespace MarketData {
28 
29 /// List of known errors.
30 struct ONIXS_BME_SENAF_EXPORT KnownErrors
31 {
32  /// \copydoc KnownErrors
33  enum Enum
34  {
35  /// Indicates absence of error.
37 
38  /// Identifiers errors of generic nature.
40 
41  /// Indicates License-related issues like
42  /// there's no license available or license
43  /// has been expired.
45 
46  /// Handler configuration is invalid.
48 
49  /// Network packet received by the Handler is corrupted.
51  };
52 
53  /// Returns string presentation of a value.
54  static const char* toString(Enum value);
55 };
56 
57 /// Error code.
59 
60 /// Error.
61 class ONIXS_BME_SENAF_EXPORT Error : public std::exception
62 {
63 public:
64  /// Initializes instance with just a code.
65  Error(const std::string& source, ErrorCode code);
66 
67  /// Initializes instance with code and description.
68  Error(const std::string& source, ErrorCode code, const std::string& description);
69 
70  /// Initializes as clone of another error.
71  Error(const Error& other);
72 
73  /// Destruction interface.
74  virtual ~Error() throw();
75 
76  /// Code of error.
77  ErrorCode code() const;
78 
79  /// Human readable description of error.
80  const char* description() const;
81 
82  /// Origin of the error.
83  const char* source() const;
84 
85  /// Human readable description of error.
86  virtual const char* what() const throw();
87 
88  /// String presentation of an error.
89  std::string toString() const;
90 
91  /// Appends presentation of an error to the string.
92  void toString(std::string&) const;
93 
94  /// Copies error attributes from another instance.
95  Error& operator=(const Error& other);
96 
97 private:
98  enum Traits
99  {
100  SourceMaxLength = 128
101  , DescriptionMaxLength = 1024
102  };
103 
104  ErrorCode code_;
105  char source_[SourceMaxLength];
106  char description_[DescriptionMaxLength];
107 };
108 
109 /// Make it printable to formatted C++ I/O streams.
110 ONIXS_BME_SENAF_EXPORT std::ostream& operator<<(std::ostream&, const Error&);
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 }}} // namespace MarketData, Senaf, OnixS
List of known errors.
Definition: Error.h:30
Handler configuration is invalid.
Definition: Error.h:47
const char * source() const
Origin of the error.
Definition: Error.h:122
ErrorCode code() const
Code of error.
Definition: Error.h:112
Enum
List of known errors.
Definition: Error.h:33
Identifiers errors of generic nature.
Definition: Error.h:39
std::ostream & operator<<(std::ostream &, const Error &)
Make it printable to formatted C++ I/O streams.
std::string toString() const
String presentation of an error.
Definition: Error.h:127
Indicates absence of error.
Definition: Error.h:36
KnownErrors::Enum ErrorCode
Error code.
Definition: Error.h:58
const char * description() const
Human readable description of error.
Definition: Error.h:117
Network packet received by the Handler is corrupted.
Definition: Error.h:50