@@ -20,16 +20,81 @@ namespace libserial {
2020 */
2121class SerialException : public std ::exception {
2222public:
23- explicit SerialException (std::string message) : message_(std::move(message)) {
23+ explicit SerialException (std::string message)
24+ : message_(std::move(message)) {
2425}
25-
2626const char * what () const noexcept override {
2727 return message_.c_str ();
2828}
29+ private:
30+ std::string message_;
31+ }; // class SerialException
2932
33+ /* *
34+ * @class PortNotFoundException
35+ * @brief Exception class for port not found errors
36+ *
37+ * The PortNotFoundException class is derived from SerialException
38+ * and is used to indicate that a specified serial port could not be found.
39+ */
40+ class PortNotFoundException : public SerialException {
41+ public:
42+ explicit PortNotFoundException (std::string message)
43+ : SerialException(std::move(message)) {}
44+ const char * what () const noexcept override { return message_.c_str (); }
3045private:
31- std::string message_; // NOLINT(runtime/string)
32- };
33- } // namespace libserial
46+ std::string message_;
47+ }; // class PortNotFoundException
48+
49+ /* *
50+ * @class PermissionDeniedException
51+ * @brief Exception class for permission denied errors
52+ *
53+ * The PermissionDeniedException class is derived from SerialException
54+ * and is used to indicate that permission to access a specified serial port was denied.
55+ */
56+ class PermissionDeniedException : public SerialException {
57+ public:
58+ explicit PermissionDeniedException (std::string message)
59+ : SerialException(std::move(message)) {}
60+ const char * what () const noexcept override { return message_.c_str (); }
61+ private:
62+ std::string message_;
63+ }; // class PermissionDeniedException
64+
65+ /* *
66+ * @class TimeoutException
67+ * @brief Exception class for timeout errors
68+ *
69+ * The TimeoutException class is derived from SerialException
70+ * and is used to indicate that a serial port operation has timed out.
71+ */
72+ class TimeoutException : public SerialException {
73+ public:
74+ explicit TimeoutException (std::string message)
75+ : SerialException(std::move(message)) {}
76+ const char * what () const noexcept override { return message_.c_str (); }
77+ private:
78+ std::string message_;
79+ }; // class TimeoutException
80+
81+ /* *
82+ * @class IOException
83+ * @brief Exception class for I/O errors
84+ *
85+ * The IOException class is derived from SerialException
86+ * and is used to indicate that an I/O error has occurred during
87+ * serial port operations.
88+ */
89+ class IOException : public SerialException {
90+ public:
91+ explicit IOException (std::string message)
92+ : SerialException(std::move(message)) {}
93+ const char * what () const noexcept override { return message_.c_str (); }
94+ private:
95+ std::string message_;
96+ }; // class IOException
97+
98+ }; // namespace libserial
3499
35100#endif // INCLUDE_LIBSERIAL_SERIAL_EXCEPTION_HPP_
0 commit comments