Paho C++  1.0
The Paho MQTT C++ Client Library
 All Classes Files Functions Variables Typedefs Friends
exception.h
Go to the documentation of this file.
1 
8 /*******************************************************************************
9  * Copyright (c) 2013-2016 Frank Pagliughi <fpagliughi@mindspring.com>
10  *
11  * All rights reserved. This program and the accompanying materials
12  * are made available under the terms of the Eclipse Public License v1.0
13  * and Eclipse Distribution License v1.0 which accompany this distribution.
14  *
15  * The Eclipse Public License is available at
16  * http://www.eclipse.org/legal/epl-v10.html
17  * and the Eclipse Distribution License is available at
18  * http://www.eclipse.org/org/documents/edl-v10.php.
19  *
20  * Contributors:
21  * Frank Pagliughi - initial implementation and documentation
22  *******************************************************************************/
23 
24 #ifndef __mqtt_exception_h
25 #define __mqtt_exception_h
26 
27 #include "MQTTAsync.h"
28 #include "mqtt/types.h"
29 #include <vector>
30 #include <memory>
31 #include <exception>
32 #include <stdexcept>
33 
34 namespace mqtt {
35 
37 
42 class exception : public std::runtime_error
43 {
44 protected:
46  int code_;
48  string msg_;
49 
50 public:
55  explicit exception(int code)
56  : std::runtime_error("MQTT error ["+std::to_string(code)+"]"), code_(code) {}
62  exception(int code, const string& msg) :
63  std::runtime_error("MQTT error ["+std::to_string(code)+"]: "+msg),
64  code_(code), msg_(msg) {}
68  string get_message() const { return msg_; }
72  int get_reason_code() const { return code_; }
77  string to_string() const { return string(what()); }
78 };
79 
81 
87 {
88 public:
92  persistence_exception() : exception(MQTTCLIENT_PERSISTENCE_ERROR) {}
97  explicit persistence_exception(int code) : exception(code) {}
102  explicit persistence_exception(const string& msg)
103  : exception(MQTTCLIENT_PERSISTENCE_ERROR, msg) {}
109  persistence_exception(int code, const string& msg)
110  : exception(code, msg) {}
111 };
112 
114 
120 {
121 public:
126  explicit security_exception(int code) : exception(code) {}
132  security_exception(int code, const string& msg) : exception(code, msg) {}
133 };
134 
136 // end namespace mqtt
137 }
138 
139 #endif // __mqtt_token_h
persistence_exception(int code, const string &msg)
Creates an MQTT persistence exception.
Definition: exception.h:109
Basic types and type conversions for the Paho MQTT C++ library.
int get_reason_code() const
Returns the reason code for this exception.
Definition: exception.h:72
persistence_exception(const string &msg)
Creates an MQTT persistence exception.
Definition: exception.h:102
This exception is thrown by the implementor of the persistence interface if there is a problem readin...
Definition: exception.h:86
string msg_
The error message from the C library.
Definition: exception.h:48
security_exception(int code, const string &msg)
Creates an MQTT security exception.
Definition: exception.h:132
string to_string() const
Gets a string representation of this exception.
Definition: exception.h:77
Base mqtt::exception.
Definition: exception.h:42
int code_
The error code from the C library.
Definition: exception.h:46
Thrown when a client is not authorized to perform an operation, or if there is a problem with the sec...
Definition: exception.h:119
persistence_exception(int code)
Creates an MQTT persistence exception.
Definition: exception.h:97
exception(int code)
Creates an MQTT exception.
Definition: exception.h:55
exception(int code, const string &msg)
Creates an MQTT exception.
Definition: exception.h:62
persistence_exception()
Creates an MQTT persistence exception.
Definition: exception.h:92
string get_message() const
Returns the error message for this exception.
Definition: exception.h:68
security_exception(int code)
Creates an MQTT security exception.
Definition: exception.h:126