Skip to content

Commit f911226

Browse files
committed
✨ feat(exceptions): Implemented especific exceptions
1 parent 4096d6a commit f911226

File tree

1 file changed

+70
-5
lines changed

1 file changed

+70
-5
lines changed

include/libserial/serial_exception.hpp

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,81 @@ namespace libserial {
2020
*/
2121
class SerialException : public std::exception {
2222
public:
23-
explicit SerialException(std::string message) : message_(std::move(message)) {
23+
explicit SerialException(std::string message)
24+
: message_(std::move(message)) {
2425
}
25-
2626
const 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(); }
3045
private:
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

Comments
 (0)