RTC Toolkit 6.0.0-pre2
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1
12
13#ifndef RTCTK_COMPONENTFRAMEWORK_EXCEPTIONS_HPP
14#define RTCTK_COMPONENTFRAMEWORK_EXCEPTIONS_HPP
15
16#include <rtctk/config.hpp>
17
18#include <ciiBasicDataType.hpp>
19#include <ciiException.hpp>
20
21#include <concepts>
22#include <string_view>
23#include <type_traits>
24#include <typeinfo>
25
26// We temporarily redefine broken CII macros.
27// TODO: Remove the redefinitions once they are fixed.
28
29#ifdef CII_MAKE_EXCEPTION
30#undef CII_MAKE_EXCEPTION
31
32#define CII_MAKE_EXCEPTION(exceptionType_t, ...) \
33 ::error::elt::details::CreateExceptionObject<exceptionType_t>( \
34 0, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
35
36#endif // CII_MAKE_EXCEPTION
37
38#ifdef CII_MAKE_EXCEPTION_WITH_NESTED
39#undef CII_MAKE_EXCEPTION_WITH_NESTED
40
41#define CII_MAKE_EXCEPTION_WITH_NESTED(exceptionType_t, nested_exception, ...) \
42 ::error::elt::details::CreateExceptionObject<exceptionType_t>( \
43 nested_exception, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
44
45#endif // CII_MAKE_EXCEPTION_WITH_NESTED
46
48namespace detail {
49
57template <class T>
58struct UnspecifiedNested : virtual T, virtual std::nested_exception {
59 template <class E>
60 requires std::constructible_from<T, E>
61 explicit UnspecifiedNested(E&& e) noexcept(std::is_nothrow_constructible_v<T, E&&>)
62 : T(std::forward<E>(e)) {
63 }
64};
65
71std::ostream& JoinLines(std::ostream& os,
72 std::string_view lines,
73 std::string_view initial_indent,
74 std::string_view subsequent_indent);
75
76} // namespace detail
77
96template <class E>
97auto WrapWithNested(E&& exception) noexcept(
98 std::is_nothrow_constructible_v<detail::UnspecifiedNested<typename std::decay_t<E>>, E&&>) {
99 using Type = typename std::decay_t<E>;
100 static_assert(std::is_class_v<Type>, "exception must be a non-union class-type");
101
102 return detail::UnspecifiedNested<Type>(std::forward<E>(exception));
103}
104
119void PrintComposedExceptions(std::ostream& os, const std::vector<std::exception_ptr>& exceptions);
120
135void PrintNestedExceptions(std::ostream& os, const std::exception& exception);
136
147void PrintNestedExceptions(std::ostream& os, std::exception_ptr ptr);
148
162public:
166 explicit NestedExceptionPrinter(const std::exception& exception) noexcept
167 : m_ptr(), m_exception(&exception) {};
168
171 explicit NestedExceptionPrinter(std::exception_ptr ptr) noexcept
172 : m_ptr(std::move(ptr)), m_exception(nullptr) {};
173
179 std::string Str() const {
180 std::stringstream ss;
181 ss << *this;
182 return ss.str();
183 }
184
192 friend std::ostream& operator<<(std::ostream& os, const NestedExceptionPrinter& printer) {
193 if (printer.m_ptr) {
194 PrintNestedExceptions(os, printer.m_ptr);
195 } else if (printer.m_exception) {
196 PrintNestedExceptions(os, *printer.m_exception);
197 }
198 return os;
199 }
200
201private:
202 // A variant or union would occupy same space so this was preferred over
203 // including <variant>
204 std::exception_ptr m_ptr;
205 const std::exception* m_exception;
206};
207
213class RtctkException : public elt::error::CiiBaseException {
214public:
215 RtctkException() noexcept;
216
217 explicit RtctkException(const std::string& msg);
218
219 RtctkException(const RtctkException& other) noexcept;
220
221 ~RtctkException() override = default;
222};
223
231public:
232 explicit NotImplementedException(const std::string& feature);
233};
234
242public:
243 explicit UnsupportedTypeException(const std::string& type);
244 explicit UnsupportedTypeException(const std::type_info& type);
245 explicit UnsupportedTypeException(const elt::common::CiiBasicDataType type);
246};
247
255public:
256 explicit UnsupportedUriException(const elt::mal::Uri& uri);
257 explicit UnsupportedUriException(const std::string& context, const elt::mal::Uri& uri);
258};
259
267public:
273 explicit BufferTooSmall(const std::size_t actual, const std::size_t expected);
274
281 explicit BufferTooSmall(const std::size_t actual,
282 const std::size_t expected,
283 const std::string& reason);
284
285 std::size_t GetActualBufferSize() const {
286 return m_actual;
287 }
288 std::size_t GetExpectedBufferSize() const {
289 return m_expected;
290 }
291
292protected:
293 std::size_t m_actual;
294 std::size_t m_expected;
295};
296
303public:
304 explicit InvalidArgumentException(const std::string& message);
305};
306
316public:
317 explicit InitialisationException(const std::string& message);
318};
319
327public:
329 explicit InvalidStateChange(const std::string& message)
330 : RtctkException("Invalid Operation: " + message) {
331 }
332};
333
341public:
343 explicit InvalidSetting(const std::string& message)
344 : RtctkException("Invalid Setting: " + message) {
345 }
346};
347
355public:
357 explicit DdtSinkNotFound(const std::string& message)
358 : RtctkException("DDT Sink not found: " + message) {
359 }
360};
361
369class DdtError : public RtctkException {
370public:
372 explicit DdtError(const std::string& message)
373 : RtctkException("Error in DDT Publisher: " + message) {
374 }
375};
376
384class IpcqError : public RtctkException {
385public:
387 explicit IpcqError(const std::string& message) : RtctkException("Error in IPCQ: " + message) {
388 }
389};
390
398public:
399 explicit AdapterCreationException(const std::string& interface_name);
400};
401
402} // namespace rtctk::componentFramework
403
404#endif // RTCTK_COMPONENTFRAMEWORK_EXCEPTIONS_HPP
InvalidArgumentException(const std::string &message)
Definition exceptions.cpp:180
AdapterCreationException(const std::string &interface_name)
Definition exceptions.cpp:192
std::size_t m_actual
Definition exceptions.hpp:293
std::size_t GetActualBufferSize() const
Definition exceptions.hpp:285
std::size_t m_expected
Definition exceptions.hpp:294
BufferTooSmall(const std::size_t actual, const std::size_t expected)
Construct exception object.
Definition exceptions.cpp:159
std::size_t GetExpectedBufferSize() const
Definition exceptions.hpp:288
RtctkException() noexcept
Definition exceptions.cpp:113
DdtError(const std::string &message)
Definition exceptions.hpp:372
RtctkException() noexcept
Definition exceptions.cpp:113
DdtSinkNotFound(const std::string &message)
Definition exceptions.hpp:357
InitialisationException(const std::string &message)
Definition exceptions.cpp:186
InvalidArgumentException(const std::string &message)
Definition exceptions.cpp:180
InvalidSetting(const std::string &message)
Definition exceptions.hpp:343
RtctkException() noexcept
Definition exceptions.cpp:113
InvalidStateChange(const std::string &message)
Definition exceptions.hpp:329
RtctkException() noexcept
Definition exceptions.cpp:113
RtctkException() noexcept
Definition exceptions.cpp:113
IpcqError(const std::string &message)
Definition exceptions.hpp:387
std::string Str() const
Convenience function for constructing a std::string from the exception.
Definition exceptions.hpp:179
NestedExceptionPrinter(const std::exception &exception) noexcept
Construct from exception derived from std::exception.
Definition exceptions.hpp:166
NestedExceptionPrinter(std::exception_ptr ptr) noexcept
Construct from exception_ptr.
Definition exceptions.hpp:171
friend std::ostream & operator<<(std::ostream &os, const NestedExceptionPrinter &printer)
Formats exception from printer using PrintNestedExceptions.
Definition exceptions.hpp:192
NotImplementedException(const std::string &feature)
Definition exceptions.cpp:124
RtctkException() noexcept
Definition exceptions.cpp:113
RtctkException(const RtctkException &other) noexcept
UnsupportedTypeException(const std::string &type)
Definition exceptions.cpp:131
UnsupportedUriException(const elt::mal::Uri &uri)
Definition exceptions.cpp:148
Project-wide configuration header.
#define RTCTK_API
Helper to indicate that a class or function must be exported in the public symbol table.
Definition config.hpp:33
Definition measurable.hpp:26
std::ostream & JoinLines(std::ostream &os, std::string_view lines, std::string_view initial_indent, std::string_view subsequent_indent)
Join each line in lines with.
Definition exceptions.cpp:26
Definition commandReplier.cpp:22
void PrintNestedExceptions(std::ostream &os, const std::exception &exception)
Print nested exception(s) in exception messages to os.
Definition exceptions.cpp:213
void PrintComposedExceptions(std::ostream &os, const std::vector< std::exception_ptr > &exceptions)
Print composed exception(s) in exception messages to os.
Definition exceptions.cpp:198
auto WrapWithNested(E &&exception) noexcept(std::is_nothrow_constructible_v< detail::UnspecifiedNested< typename std::decay_t< E > >, E && >)
Constructs an unspecified exception that derives from both the provided object and std::nested_except...
Definition exceptions.hpp:97
Definition ddsSub.hpp:156
Unspecified exception used by WrapWithNested.
Definition exceptions.hpp:58
UnspecifiedNested(E &&e) noexcept(std::is_nothrow_constructible_v< T, E && >)
Definition exceptions.hpp:61