AMPS C/C++ Client Class Reference AMPS C/C++ Client Version 5.3.5.4

AMPSException.hpp
1 //
3 // Copyright (c) 2010-2026 60East Technologies Inc., All Rights Reserved.
4 //
5 // This computer software is owned by 60East Technologies Inc. and is
6 // protected by U.S. copyright laws and other laws and by international
7 // treaties. This computer software is furnished by 60East Technologies
8 // Inc. pursuant to a written license agreement and may be used, copied,
9 // transmitted, and stored only in accordance with the terms of such
10 // license agreement and with the inclusion of the above copyright notice.
11 // This computer software or any other copies thereof may not be provided
12 // or otherwise made available to any other person.
13 //
14 // U.S. Government Restricted Rights. This computer software: (a) was
15 // developed at private expense and is in all respects the proprietary
16 // information of 60East Technologies Inc.; (b) was not developed with
17 // government funds; (c) is a trade secret of 60East Technologies Inc.
18 // for all purposes of the Freedom of Information Act; and (d) is a
19 // commercial item and thus, pursuant to Section 12.212 of the Federal
20 // Acquisition Regulations (FAR) and DFAR Supplement Section 227.7202,
21 // Government's use, duplication or disclosure of the computer software
22 // is subject to the restrictions set forth by 60East Technologies Inc..
23 //
25 #ifndef __AMPSEXCEPTION_HPP_
26 #define __AMPSEXCEPTION_HPP_
27 #define _AMPS_SKIP_AMPSPLUSPLUS
28 #include <amps/amps.h>
29 #undef _AMPS_SKIP_AMPSPLUSPLUS
30 #include <stdexcept>
31
32 namespace AMPS
33 {
40 class AMPSException : public std::runtime_error
41 {
42 protected:
43 amps_result _result;
44 public:
50 AMPSException(const std::string& message_,
51 amps_result result_)
52 : std::runtime_error(message_),
53 _result(result_)
54 {
55 }
56
63 AMPSException(amps_handle client_,
64 amps_result result_)
65 : std::runtime_error(""),
66 _result(result_)
67 {
68 char buffer[1024];
69 amps_client_get_error(client_, buffer,
70 sizeof(buffer));
71 buffer[sizeof(buffer) - 1] = '\0';
72 (std::runtime_error&)*this = std::runtime_error(buffer);
73 }
74 virtual ~AMPSException() {;}
75
80 const char* toString() const
81 {
82 return what();
83 }
84
90 virtual const char* getClassName() const
91 {
92 return "AMPSException";
93 }
94
100 template <class T>
101 static void throwFor(const T& context_, amps_result result_);
102 };
103
104 #define AMPS_EX_TYPE(x, b) \
105 class x : public b\
106 {\
107 public:\
108 x(const std::string& message, amps_result result = AMPS_E_OK)\
109 : b(message, result)\
110 {\
111 ;\
112 }\
113 x(amps_handle client, amps_result result)\
114 : b(client, result)\
115 {\
116 ;\
117 }\
118 virtual const char* getClassName() const\
119 {\
120 return #x;\
121 }\
122 };
123 AMPS_EX_TYPE(CommandException, AMPSException)
124 AMPS_EX_TYPE(ConnectionException, AMPSException)
125 AMPS_EX_TYPE(UsageException, AMPSException)
126 AMPS_EX_TYPE(StoreException, AMPSException)
127 AMPS_EX_TYPE(MessageStreamFullException, AMPSException)
128 AMPS_EX_TYPE(ConnectionRefusedException, ConnectionException)
129 AMPS_EX_TYPE(DisconnectedException, ConnectionException)
130 AMPS_EX_TYPE(AlreadyConnectedException, ConnectionException)
131 AMPS_EX_TYPE(AuthenticationException, ConnectionException)
132 AMPS_EX_TYPE(InvalidURIException, ConnectionException)
133 AMPS_EX_TYPE(NameInUseException, ConnectionException)
134 AMPS_EX_TYPE(NotEntitledException, ConnectionException)
135 AMPS_EX_TYPE(ReconnectMaximumExceededException, ConnectionException)
136 AMPS_EX_TYPE(RetryOperationException, ConnectionException)
137 AMPS_EX_TYPE(TimedOutException, ConnectionException)
138 AMPS_EX_TYPE(TransportTypeException, ConnectionException)
139 AMPS_EX_TYPE(BadFilterException, CommandException)
140 AMPS_EX_TYPE(BadSowKeyException, CommandException)
141 AMPS_EX_TYPE(BadRegexTopicException, CommandException)
142 AMPS_EX_TYPE(DuplicateLogonException, CommandException)
143 AMPS_EX_TYPE(InvalidBookmarkException, CommandException)
144 AMPS_EX_TYPE(InvalidOptionsException, CommandException)
145 AMPS_EX_TYPE(InvalidOrderByException, CommandException)
146 AMPS_EX_TYPE(InvalidSubIdException, CommandException)
147 AMPS_EX_TYPE(InvalidTopicException, CommandException)
148 AMPS_EX_TYPE(LogonRequiredException, CommandException)
149 AMPS_EX_TYPE(MissingFieldsException, CommandException)
150 AMPS_EX_TYPE(PublishException, CommandException)
151 AMPS_EX_TYPE(SubscriptionAlreadyExistsException, CommandException)
152 AMPS_EX_TYPE(SubidInUseException, CommandException)
153 AMPS_EX_TYPE(UnknownException, CommandException)
154 AMPS_EX_TYPE(ReplayFailedException, CommandException)
155 AMPS_EX_TYPE(PublishStoreGapException, StoreException)
156
157 template <class T>
158 void AMPSException::throwFor(const T& context_, amps_result result_)
159 {
160 switch (result_)
161 {
162 case AMPS_E_OK:
163 return;
164 case AMPS_E_COMMAND:
165 throw CommandException(context_, result_);
166 case AMPS_E_CONNECTION:
167 throw ConnectionException(context_, result_);
168 case AMPS_E_TOPIC:
169 throw InvalidTopicException(context_, result_);
170 case AMPS_E_FILTER:
171 throw BadFilterException(context_, result_);
172 case AMPS_E_RETRY:
173 throw RetryOperationException(context_, result_);
174 case AMPS_E_DISCONNECTED:
175 throw DisconnectedException(context_, result_);
176 case AMPS_E_CONNECTION_REFUSED:
177 throw ConnectionRefusedException(context_, result_);
178 case AMPS_E_URI:
179 throw InvalidURIException(context_, result_);
180 case AMPS_E_TRANSPORT_TYPE:
181 throw TransportTypeException(context_, result_);
182 case AMPS_E_USAGE:
183 throw UsageException(context_, result_);
184 default:
185 throw AMPSException(context_, result_);
186 }
187 }
188 }
189 #endif
190
amps.h
Core type and function declarations for the AMPS C client.
amps_result
amps_result
Return values from amps_xxx functions.
Definition: amps.h:217
AMPS_E_RETRY
@ AMPS_E_RETRY
The operation has not succeeded, but ought to be retried.
Definition: amps.h:245
AMPS_E_USAGE
@ AMPS_E_USAGE
The usage of this function is invalid.
Definition: amps.h:269
AMPS_E_URI
@ AMPS_E_URI
The specified URI is invalid.
Definition: amps.h:261
AMPS_E_OK
@ AMPS_E_OK
Success.
Definition: amps.h:221
AMPS_E_DISCONNECTED
@ AMPS_E_DISCONNECTED
The client and server are disconnected.
Definition: amps.h:249
AMPS_E_COMMAND
@ AMPS_E_COMMAND
An error with a command occurred.
Definition: amps.h:229
AMPS_E_TRANSPORT_TYPE
@ AMPS_E_TRANSPORT_TYPE
The specified transport type is invalid.
Definition: amps.h:265
AMPS_E_TOPIC
@ AMPS_E_TOPIC
The specified topic was invalid.
Definition: amps.h:237
AMPS_E_CONNECTION_REFUSED
@ AMPS_E_CONNECTION_REFUSED
The server could not be found, or it actively refused our connection.
Definition: amps.h:253
AMPS_E_CONNECTION
@ AMPS_E_CONNECTION
A connection error occurred.
Definition: amps.h:233
AMPS_E_FILTER
@ AMPS_E_FILTER
The specified filter was invalid.
Definition: amps.h:241
amps_client_get_error
AMPSDLL size_t amps_client_get_error(amps_handle client, amps_char *errorMessageOut, size_t bufferSize)
Returns the last error set on this client.
amps_handle
void * amps_handle
Opaque handle type used to refer to objects in the AMPS api.
Definition: amps.h:211
AMPS::AMPSException
Base class for all exceptions in AMPS.
Definition: AMPSException.hpp:41
AMPS::AMPSException::AMPSException
AMPSException(const std::string &message_, amps_result result_)
Construct an AMPSException from a text message.
Definition: AMPSException.hpp:50
AMPS::AMPSException::toString
const char * toString() const
Returns a null-terminated string containing self's error message.
Definition: AMPSException.hpp:80
AMPS::AMPSException::throwFor
static void throwFor(const T &context_, amps_result result_)
Constructs and throws the appropriate exception corresponding to a given result.
AMPS::AMPSException::getClassName
virtual const char * getClassName() const
Returns the actual name of the subclass thrown – useful when RTTI is disabled, but you'd still like t...
Definition: AMPSException.hpp:90
AMPS::AMPSException::AMPSException
AMPSException(amps_handle client_, amps_result result_)
Construct an AMPSException from the last error message on client.
Definition: AMPSException.hpp:63