OnixS BME SENAF Handler C++ library  2.2.1
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
5  * copyright law and international copyright treaties.
6  *
7  * Access to and use of the software is governed by the terms of the applicable
8  * ONIXS Software Services Agreement (the Agreement) and Customer end user
9  * license agreements granting a non-assignable, non-transferable and
10  * non-exclusive license to use the software for it's own data processing
11  * purposes under the terms defined in the Agreement.
12  *
13  * Except as otherwise granted within the terms of the Agreement, copying or
14  * reproduction of any part of this source code or associated reference material
15  * to any other location for further reproduction or redistribution, and any
16  * amendments to this copyright notice, are expressly prohibited.
17  *
18  * Any reproduction or redistribution for sale or hiring of the Software not in
19  * accordance with the terms of the Agreement is a violation of copyright law.
20  */
21 
22 #pragma once
23 
24 #include <OnixS/Senaf/MarketData/Export.h>
25 
26 #include <iosfwd>
27 #include <string>
28 
29 namespace OnixS { namespace Senaf { namespace MarketData {
30 
31 /// List of known errors.
32 struct ONIXS_BME_SENAF_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 
55  /// Returns string presentation of a value.
56  static const char* toString(Enum value);
57 };
58 
59 /// Error code.
61 
62 /// Error.
63 class ONIXS_BME_SENAF_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];
108  char description_[DescriptionMaxLength];
109 };
110 
111 /// Make it printable to formatted C++ I/O streams.
112 ONIXS_BME_SENAF_EXPORT std::ostream& operator<<(std::ostream&, const Error&);
113 
114 inline ErrorCode Error::code() const
115 {
116  return code_;
117 }
118 
119 inline const char* Error::description() const
120 {
121  return description_;
122 }
123 
124 inline const char* Error::source() const
125 {
126  return source_;
127 }
128 
129 inline std::string Error::toString() const
130 {
131  std::string str;
132  toString(str);
133  return str;
134 }
135 
136 }}} // namespace OnixS::Senaf::MarketData
List of known errors.
Definition: Error.h:32
Handler configuration is invalid.
Definition: Error.h:49
const char * source() const
Origin of the error.
Definition: Error.h:124
ErrorCode code() const
Code of error.
Definition: Error.h:114
Enum
List of known errors.
Definition: Error.h:35
Identifiers errors of generic nature.
Definition: Error.h:41
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:129
Indicates absence of error.
Definition: Error.h:38
KnownErrors::Enum ErrorCode
Error code.
Definition: Error.h:60
const char * description() const
Human readable description of error.
Definition: Error.h:119
Network packet received by the Handler is corrupted.
Definition: Error.h:52