mqtt_cpp
exception.hpp
Go to the documentation of this file.
1 // Copyright Takatoshi Kondo 2015
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #if !defined(MQTT_EXCEPTION_HPP)
8 #define MQTT_EXCEPTION_HPP
9 
10 #include <exception>
11 #include <sstream>
12 
13 #include <boost/system/error_code.hpp>
14 #include <boost/assert.hpp>
15 
16 #include <mqtt/namespace.hpp>
18 
19 namespace MQTT_NS {
20 
21 struct protocol_error : std::exception {
22  char const* what() const noexcept override final {
23  return "protocol error";
24  }
25 };
26 
27 struct malformed_packet_error : std::exception {
28  char const* what() const noexcept override final {
29  return "malformed packet error";
30  }
31 };
32 
33 struct remaining_length_error : std::exception {
34  char const* what() const noexcept override final {
35  return "remaining length error";
36  }
37 };
38 
39 struct variable_length_error : std::exception {
40  char const* what() const noexcept override final {
41  return "variable length error";
42  }
43 };
44 
45 struct utf8string_length_error : std::exception {
46  char const* what() const noexcept override final {
47  return "utf8string length error";
48  }
49 };
50 
51 struct utf8string_contents_error : std::exception {
53  char const* what() const noexcept override final {
55  return "utf8string ill_formed";
56  }
57  else {
59  return "utf8string well_formed_with_non_charactor";
60  }
61  }
63 };
64 
65 struct will_message_length_error : std::exception {
66  char const* what() const noexcept override final {
67  return "will message length error";
68  }
69 };
70 
71 struct password_length_error : std::exception {
72  char const* what() const noexcept override final {
73  return "password length error";
74  }
75 };
76 
77 struct bytes_transferred_error : std::exception {
78  bytes_transferred_error(std::size_t expected, std::size_t actual) {
79  std::stringstream ss;
80  ss << "bytes transferred error. expected: " << expected << " actual: " << actual;
81  msg = ss.str();
82  }
83  char const* what() const noexcept override final {
84  return msg.data();
85  }
86  std::string msg;
87 };
88 
90  read_bytes_transferred_error(std::size_t expected, std::size_t actual)
91  :bytes_transferred_error(expected, actual) {
92  msg = "[read] " + msg;
93  }
94 };
95 
97  write_bytes_transferred_error(std::size_t expected, std::size_t actual)
98  :bytes_transferred_error(expected, actual) {
99  msg = "[write] " + msg;
100  }
101 };
102 
103 struct packet_id_exhausted_error : std::exception {
104  char const* what() const noexcept override final {
105  return "packet_id exhausted error";
106  }
107 };
108 
109 struct property_parse_error : std::exception {
110  char const* what() const noexcept override final {
111  return "property parse error";
112  }
113 };
114 
115 struct property_length_error : std::exception {
116  char const* what() const noexcept override final {
117  return "property length error";
118  }
119 };
120 
121 struct restore_type_error : std::exception {
122  char const* what() const noexcept override final {
123  return "restore type error";
124  }
125 };
126 
127 } // namespace MQTT_NS
128 
129 #endif // MQTT_EXCEPTION_HPP
validation
Definition: utf8encoded_strings.hpp:18
@ ill_formed
UTF-8 string is ill_formed or contains null character. See http://docs.oasis-open....
@ well_formed_with_non_charactor
UTF-8 string is well_formed and contains control character and non-character. See http://docs....
Definition: any.hpp:27
Definition: exception.hpp:77
bytes_transferred_error(std::size_t expected, std::size_t actual)
Definition: exception.hpp:78
std::string msg
Definition: exception.hpp:86
char const * what() const noexcept override final
Definition: exception.hpp:83
Definition: exception.hpp:27
char const * what() const noexcept override final
Definition: exception.hpp:28
Definition: exception.hpp:103
char const * what() const noexcept override final
Definition: exception.hpp:104
Definition: exception.hpp:71
char const * what() const noexcept override final
Definition: exception.hpp:72
Definition: exception.hpp:115
char const * what() const noexcept override final
Definition: exception.hpp:116
Definition: exception.hpp:109
char const * what() const noexcept override final
Definition: exception.hpp:110
Definition: exception.hpp:21
char const * what() const noexcept override final
Definition: exception.hpp:22
Definition: exception.hpp:89
read_bytes_transferred_error(std::size_t expected, std::size_t actual)
Definition: exception.hpp:90
Definition: exception.hpp:33
char const * what() const noexcept override final
Definition: exception.hpp:34
Definition: exception.hpp:121
char const * what() const noexcept override final
Definition: exception.hpp:122
Definition: exception.hpp:51
char const * what() const noexcept override final
Definition: exception.hpp:53
utf8string::validation r
Definition: exception.hpp:62
utf8string_contents_error(utf8string::validation r)
Definition: exception.hpp:52
Definition: exception.hpp:45
char const * what() const noexcept override final
Definition: exception.hpp:46
Definition: exception.hpp:39
char const * what() const noexcept override final
Definition: exception.hpp:40
Definition: exception.hpp:65
char const * what() const noexcept override final
Definition: exception.hpp:66
Definition: exception.hpp:96
write_bytes_transferred_error(std::size_t expected, std::size_t actual)
Definition: exception.hpp:97