OnixS BME SENAF Handler C++ library 2.3.0
API documentation
Loading...
Searching...
No Matches
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
29namespace OnixS { namespace Senaf { namespace MarketData {
30
32struct ONIXS_BME_SENAF_EXPORT KnownErrors
33{
54
56 static const char* toString(Enum value);
57};
58
61
63class ONIXS_BME_SENAF_EXPORT Error : public std::exception
64{
65public:
67 Error(const std::string& source, ErrorCode code);
68
70 Error(const std::string& source, ErrorCode code, const std::string& description);
71
73 Error(const Error& other);
74
76 virtual ~Error() throw();
77
79 ErrorCode code() const;
80
82 const char* description() const;
83
85 const char* source() const;
86
88 virtual const char* what() const throw();
89
91 std::string toString() const;
92
94 void toString(std::string&) const;
95
97 Error& operator=(const Error& other);
98
99private:
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
112ONIXS_BME_SENAF_EXPORT std::ostream& operator<<(std::ostream&, const Error&);
113
114inline ErrorCode Error::code() const
115{
116 return code_;
117}
118
119inline const char* Error::description() const
120{
121 return description_;
122}
123
124inline const char* Error::source() const
125{
126 return source_;
127}
128
129inline std::string Error::toString() const
130{
131 std::string str;
132 toString(str);
133 return str;
134}
135
136}}} // namespace OnixS::Senaf::MarketData
Error(const Error &other)
Initializes as clone of another error.
std::string toString() const
String presentation of an error.
Definition Error.h:129
Error(const std::string &source, ErrorCode code, const std::string &description)
Initializes instance with code and description.
const char * source() const
Origin of the error.
Definition Error.h:124
virtual ~Error()
Destruction interface.
ErrorCode code() const
Code of error.
Definition Error.h:114
Error(const std::string &source, ErrorCode code)
Initializes instance with just a code.
virtual const char * what() const
Human readable description of error.
const char * description() const
Human readable description of error.
Definition Error.h:119
std::ostream & operator<<(std::ostream &, const Error &)
Make it printable to formatted C++ I/O streams.
KnownErrors::Enum ErrorCode
Error code.
Definition Error.h:60
List of known errors.
Definition Error.h:33
Enum
List of known errors.
Definition Error.h:36
@ Nothing
Indicates absence of error.
Definition Error.h:38
@ BadConfiguration
Handler configuration is invalid.
Definition Error.h:49
@ BadPacket
Network packet received by the Handler is corrupted.
Definition Error.h:52
@ Generic
Identifiers errors of generic nature.
Definition Error.h:41
static const char * toString(Enum value)
Returns string presentation of a value.