RTC Toolkit 5.0.0
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_COMPONENTFRAMEWORK_EXCEPTIONS_HPP
14#define RTCTK_COMPONENTFRAMEWORK_EXCEPTIONS_HPP
15
16#include <string_view>
17#include <type_traits>
18#include <typeinfo>
19
20#include <ciiBasicDataType.hpp>
21#include <ciiException.hpp>
22
23#include <rtctk/config.hpp>
24
25// We temporarily redefine broken CII macros.
26// TODO: Remove the redefinitions once they are fixed.
27
28#ifdef CII_MAKE_EXCEPTION
29#undef CII_MAKE_EXCEPTION
30
31#define CII_MAKE_EXCEPTION(exceptionType_t, ...) \
32 ::error::elt::details::CreateExceptionObject<exceptionType_t>( \
33 0, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
34
35#endif // CII_MAKE_EXCEPTION
36
37#ifdef CII_MAKE_EXCEPTION_WITH_NESTED
38#undef CII_MAKE_EXCEPTION_WITH_NESTED
39
40#define CII_MAKE_EXCEPTION_WITH_NESTED(exceptionType_t, nested_exception, ...) \
41 ::error::elt::details::CreateExceptionObject<exceptionType_t>( \
42 nested_exception, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
43
44#endif // CII_MAKE_EXCEPTION_WITH_NESTED
45
47namespace detail {
48
56template <class T>
57struct UnspecifiedNested : virtual T, virtual std::nested_exception {
58 template <class E>
59 explicit UnspecifiedNested(E&& e) noexcept(std::is_nothrow_constructible_v<T, E&&>)
60 : T(std::forward<E>(e)) {
61 }
62};
63
69std::ostream& JoinLines(std::ostream& os,
70 std::string_view lines,
71 std::string_view initial_indent,
72 std::string_view subsequent_indent);
73
74} // namespace detail
75
94template <class E>
95auto WrapWithNested(E&& exception) noexcept(
96 std::is_nothrow_constructible_v<detail::UnspecifiedNested<typename std::decay_t<E>>, E&&>) {
97 using Type = typename std::decay_t<E>;
98 static_assert(std::is_class_v<Type>, "exception must be a non-union class-type");
99
100 return detail::UnspecifiedNested<Type>(std::forward<E>(exception));
101}
102
117void PrintComposedExceptions(std::ostream& os, const std::vector<std::exception_ptr>& exceptions);
118
133void PrintNestedExceptions(std::ostream& os, const std::exception& exception);
134
145void PrintNestedExceptions(std::ostream& os, std::exception_ptr ptr);
146
160public:
164 explicit NestedExceptionPrinter(const std::exception& exception) noexcept
165 : m_ptr(), m_exception(&exception) {};
169 explicit NestedExceptionPrinter(std::exception_ptr ptr) noexcept
170 : m_ptr(std::move(ptr)), m_exception(nullptr) {};
171
177 std::string Str() const {
178 std::stringstream ss;
179 ss << *this;
180 return ss.str();
181 }
182
190 friend std::ostream& operator<<(std::ostream& os, const NestedExceptionPrinter& printer) {
191 if (printer.m_ptr) {
193 } else if (printer.m_exception) {
194 PrintNestedExceptions(os, *printer.m_exception);
195 }
196 return os;
197 }
198
199private:
200 // A variant or union would occupy same space so this was preferred over
201 // including <variant>
202 std::exception_ptr m_ptr;
203 const std::exception* m_exception;
204};
205
211class RtctkException : public elt::error::CiiBaseException {
212public:
213 RtctkException() noexcept;
214
215 explicit RtctkException(const std::string& msg);
216
217 RtctkException(const RtctkException& other) noexcept;
218
219 ~RtctkException() override = default;
220};
221
229public:
230 explicit NotImplementedException(const std::string& feature);
231};
232
240public:
241 explicit UnsupportedTypeException(const std::string& type);
242 explicit UnsupportedTypeException(const std::type_info& type);
243 explicit UnsupportedTypeException(const elt::common::CiiBasicDataType type);
244};
245
253public:
254 explicit UnsupportedUriException(const elt::mal::Uri& uri);
255 explicit UnsupportedUriException(const std::string& context, const elt::mal::Uri& uri);
256};
257
265public:
271 explicit BufferTooSmall(const std::size_t actual, const std::size_t expected);
272
279 explicit BufferTooSmall(const std::size_t actual,
280 const std::size_t expected,
281 const std::string& reason);
282
283 std::size_t GetActualBufferSize() const {
284 return m_actual;
285 }
286 std::size_t GetExpectedBufferSize() const {
287 return m_expected;
288 }
289
290protected:
291 std::size_t m_actual;
292 std::size_t m_expected;
293};
294
301public:
302 explicit InvalidArgumentException(const std::string& message);
303};
304
314public:
315 explicit InitialisationException(const std::string& message);
316};
317
325public:
327 explicit InvalidStateChange(const std::string& message)
328 : RtctkException("Invalid Operation: " + message) {
329 }
330};
331
339public:
341 explicit InvalidSetting(const std::string& message)
342 : RtctkException("Invalid Setting: " + message) {
343 }
344};
345
353public:
355 explicit DdtSinkNotFound(const std::string& message)
356 : RtctkException("DDT Sink not found: " + message) {
357 }
358};
359
367class DdtError : public RtctkException {
368public:
370 explicit DdtError(const std::string& message)
371 : RtctkException("Error in DDT Publisher: " + message) {
372 }
373};
374
382class IpcqError : public RtctkException {
383public:
385 explicit IpcqError(const std::string& message) : RtctkException("Error in IPCQ: " + message) {
386 }
387};
388
396public:
397 explicit AdapterCreationException(const std::string& interface_name);
398};
399
400} // namespace rtctk::componentFramework
401
402#endif // RTCTK_COMPONENTFRAMEWORK_EXCEPTIONS_HPP
Thrown from service factory methods to indicate the adapter construction failed.
Definition exceptions.hpp:395
AdapterCreationException(const std::string &interface_name)
Definition exceptions.cpp:192
The BufferTooSmall is thrown when an API call fails because the provided buffer is not big enough to ...
Definition exceptions.hpp:264
std::size_t m_actual
Definition exceptions.hpp:291
std::size_t GetActualBufferSize() const
Definition exceptions.hpp:283
std::size_t m_expected
Definition exceptions.hpp:292
std::size_t GetExpectedBufferSize() const
Definition exceptions.hpp:286
This Exception is raised when the DDT Publisher returns an error that cannot be handled by the DDT Si...
Definition exceptions.hpp:367
DdtError(const std::string &message)
Definition exceptions.hpp:370
This Exception is raised when an invalid ddt sink is requested.
Definition exceptions.hpp:352
DdtSinkNotFound(const std::string &message)
Definition exceptions.hpp:355
Thrown in cases where an initialisation routine has failed.
Definition exceptions.hpp:313
InitialisationException(const std::string &message)
Definition exceptions.cpp:186
Thrown if an argument passed to a method was invalid.
Definition exceptions.hpp:300
InvalidArgumentException(const std::string &message)
Definition exceptions.cpp:180
This Exception is raised when a invalid setting was used in the runtime repo.
Definition exceptions.hpp:338
InvalidSetting(const std::string &message)
Definition exceptions.hpp:341
This Exception is raised when the state change requested is invalid.
Definition exceptions.hpp:324
InvalidStateChange(const std::string &message)
Definition exceptions.hpp:327
This Exception is raised when the ipc queue returns an error that cannot be handled by the Telemetry ...
Definition exceptions.hpp:382
IpcqError(const std::string &message)
Definition exceptions.hpp:385
Adapter object intended to be used in contexts without direct access to the output-stream object.
Definition exceptions.hpp:159
std::string Str() const
Convenience function for constructing a std::string from the exception.
Definition exceptions.hpp:177
NestedExceptionPrinter(const std::exception &exception) noexcept
Construct from exception derived from std::exception.
Definition exceptions.hpp:164
NestedExceptionPrinter(std::exception_ptr ptr) noexcept
Construct from exception_ptr.
Definition exceptions.hpp:169
friend std::ostream & operator<<(std::ostream &os, const NestedExceptionPrinter &printer)
Formats exception from printer using PrintNestedExceptions.
Definition exceptions.hpp:190
The NotImplementedException is thrown whenever an attempt is made to use a feature or function that h...
Definition exceptions.hpp:228
NotImplementedException(const std::string &feature)
Definition exceptions.cpp:125
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
RtctkException() noexcept
Definition exceptions.cpp:113
The UnsupportedTypeException is thrown whenever an attempt is made to use an unsupported type in the ...
Definition exceptions.hpp:239
UnsupportedTypeException(const std::string &type)
Definition exceptions.cpp:132
The UnsupportedUriException is thrown whenever an attempt is made to use an unsupported URI in the RT...
Definition exceptions.hpp:252
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
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:95
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
Unspecified exception used by WrapWithNested.
Definition exceptions.hpp:57
UnspecifiedNested(E &&e) noexcept(std::is_nothrow_constructible_v< T, E && >)
Definition exceptions.hpp:59