OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  8.1.0
API documentation
Exception.cpp
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 
21 
22 #include <OnixS/HandlerCore/Utils.h>
23 
24 #include <util/String.h>
25 
26 using namespace OnixS::Eurex::MarketData;
27 using OnixS::Util::format;
28 
29 /*
30  Exception
31 */
32 
34 {
35  size_t ref_count;
36  std::string message;
37 
38  Implementation () : ref_count (1) {}
39 };
40 
41 Exception::Exception (const char* method_name, const char* message)
42  : impl_ (new Implementation)
43 {
44  if (message && *message)
45  impl_->message += message;
46 
47  touch (method_name);
48 }
49 
51  : impl_ (e.impl_)
52 {
53  impl_->ref_count++;
54 }
55 
57 {
58  if (!--impl_->ref_count)
59  delete impl_;
60 }
61 
63 {
64  Exception tmp = e;
65 
66  std::swap (tmp.impl_, impl_);
67 
68  return *this;
69 }
70 
71 const char* Exception::what () const throw ()
72 {
73  return impl_->message.c_str ();
74 }
75 
76 void Exception::touch (const char* method_name)
77 {
78  if (!method_name || !*method_name)
79  return;
80 
81  impl_->message += "\n at ";
82  impl_->message += method_name;
83 }
84 
85 /*
86  ArgumentException
87 */
88 
89 ArgumentException::ArgumentException (const char* source, const char* message)
90  : Exception (source, message)
91 {
92 }
93 
94 ArgumentException::ArgumentException (const char* source, const char* argument_name, const char* value, const char* comment)
95  : Exception (source, format (comment ? "Bad argument %s=%s. %s": "Bad argument %s=%s", argument_name, value, comment).c_str ())
96 {
97 }
98 
99 ArgumentException::ArgumentException (const char* source, const char* argument_name, int value, const char* comment)
100  : Exception (source, format (comment ? "Bad argument %s=%d. %s": "Bad argument %s=%s", argument_name, value, comment).c_str ())
101 {
102 }
103 
104 ArgumentException::ArgumentException (const char* source, const char* argument_name, unsigned int value, const char* comment)
105  : Exception (source, format (comment ? "Bad argument %s=%u. %s": "Bad argument %s=%s", argument_name, value, comment).c_str ())
106 {
107 }
108 
109 ArgumentException::ArgumentException (const char* source, const char* argument_name, double value, const char* comment)
110  : Exception (source, format (comment ? "Bad argument %s=%g. %s": "Bad argument %s=%g", argument_name, value, comment).c_str ())
111 {
112 }
113 
114 /*
115  nullptrArgumentException
116 */
117 
118 NullArgumentException::NullArgumentException (const char* source, const char* argument_name)
119  : ArgumentException (source, format ("nullptr argument '%s'", argument_name).c_str ())
120 {
121 }
122 
123 /*
124  ArgumentRangeException
125 */
126 
127 ArgumentRangeException::ArgumentRangeException (const char* source, const char* message)
128  : ArgumentException (source, message)
129 {
130 }
131 
132 ArgumentRangeException::ArgumentRangeException (const char* source, const char* argument_name, int value, int min_value, int max_value)
133  : ArgumentException (source, format ("Argument %s=%d is out of range [%d;%d]", argument_name, value, min_value, max_value).c_str ())
134 {
135 }
136 
137 ArgumentRangeException::ArgumentRangeException (const char* source, const char* argument_name, unsigned int value, unsigned int min_value, unsigned int max_value)
138  : ArgumentException (source, format ("Argument %s=%u is out of range [%u;%u]", argument_name, value, min_value, max_value).c_str ())
139 {
140 }
141 
142 ArgumentRangeException::ArgumentRangeException (const char* source, const char* argument_name, int value, unsigned int max_value)
143  : ArgumentException (source, format ("Argument %s=%d is out of range [0;%u)", argument_name, value, max_value).c_str ())
144 {
145 }
146 
147 ArgumentRangeException::ArgumentRangeException (const char* source, const char* argument_name, unsigned int value, unsigned int max_value)
148  : ArgumentException (source, format ("Argument %s=%u is out of range [0;%u)", argument_name, value, max_value).c_str ())
149 {
150 }
151 
152 ArgumentRangeException::ArgumentRangeException (const char* source, const char* argument_name, double value, double min_value, double max_value)
153  : ArgumentException (source, format ("Argument %s=%g is out of range [%g;%g]", argument_name, value, min_value, max_value).c_str ())
154 {
155 }
156 
157 /*
158  OperationException
159 */
160 
161 OperationException::OperationException (const char* source, const char* message)
162  : Exception (source, message)
163 {
164 }
165 
166 /*
167  NotImplementedException
168 */
169 
171  : OperationException (source, format ("Method '%s' doesn't implemented", source).c_str ())
172 {
173 }
ArgumentRangeException(const char *source, const char *message)
Constructor.
Definition: Exception.cpp:127
void touch(const char *method_name)
Add information about context of exception.
Definition: Exception.cpp:76
NullArgumentException(const char *source, const char *argument_name)
Constructor.
Definition: Exception.cpp:118
Exception(const char *method_name, const char *message)
Constructor.
Definition: Exception.cpp:41
NotImplementedException(const char *source)
Constructor.
Definition: Exception.cpp:170
ArgumentException(const char *source, const char *message)
Constructor.
Definition: Exception.cpp:89
Exception & operator=(const Exception &)
Assignment.
Definition: Exception.cpp:62
OperationException(const char *source, const char *message)
Constructor.
Definition: Exception.cpp:161
Basic exception class for this namespace.
Definition: Exception.h:33
const char * what() const
Returns information about error.
Definition: Exception.cpp:71