26inline void format_nested_exception(
const std::exception& error, std::ostream& stream,
bool add_line_break =
false)
30 std::rethrow_if_nested(error);
32 catch (
const std::exception& nested_exception)
34 format_nested_exception(nested_exception, stream,
true);
40 stream <<
"exception: " << error.what();
50 const char* strFunction,
51 const tChar* strDescription =
"")
53 std::ostringstream strAnnotatedDescription;
56 << adtf::util::cFilename(oOriginal.
GetFile()).GetName().GetPtr() <<
":"
62 strAnnotatedDescription.str().c_str(),
64 adtf::util::detail::filename_with_thread_id(strFile).c_str(),
70 auto exception = std::current_exception();
75 std::rethrow_exception(exception);
78 catch(
const std::exception& error)
82 static_cast<int32_t
>(line),
83 adtf::util::cFilename(file).GetName(),
88 return annotate_result(oError, file,
static_cast<int32_t
>(line), function);
94 static_cast<int32_t
>(line),
113 std::ostringstream stream;
114 detail::format_nested_exception(error, stream);
125 auto exception = std::current_exception();
130 std::rethrow_exception(exception);
133 catch(
const std::exception& error)
139 return adtf::util::to_string(oError).GetPtr();
143 return "unknown exception";
156 return detail::current_exception_to_result(__FILE__, __LINE__, __FUNC__);
169#define ADTF_UCOM_ANNOTATE_RESULT(_result) adtf::ucom::kiwi::detail::annotate_result(_result, __FILE__, __LINE__, __FUNC__)
172#define ADTF_UCOM_COMPOSED_RESULT(_result, ...) adtf::ucom::kiwi::detail::annotate_result(_result, __FILE__, __LINE__, __FUNC__, adtf::util::cString::Format(__VA_ARGS__).GetPtr())
175#define THROW_ERROR_DESC(_code, ...) throw DETAILED_RESULT(_code, __VA_ARGS__)
177#define THROW_IF_FAILED(s) { tResult _errcode(s); if ( _errcode.IsFailed() ) { throw ADTF_UCOM_ANNOTATE_RESULT(_errcode); } }
179#define THROW_IF_FAILED_DESC(s, ...) { tResult _errcode(s); if ( _errcode.IsFailed() ) { throw ADTF_UCOM_COMPOSED_RESULT(_errcode, __VA_ARGS__); } }
182#define RETURN_CURRENT_EXCEPTION() return adtf::ucom::kiwi::detail::current_exception_to_result(__FILE__, __LINE__, __FUNC__)
184#define RETURN_CURRENT_EXCEPTION_DESC(...) return ADTF_UCOM_COMPOSED_RESULT(adtf::ucom::kiwi::detail::current_exception_to_result(__FILE__, __LINE__, __FUNC__), __VA_ARGS__)
187#define RETURN_IF_THROWS(s) { try { (s); } catch(...) { RETURN_CURRENT_EXCEPTION(); } }
189#define RETURN_IF_THROWS_DESC(s, ...) { try { (s); } catch(...) { RETURN_CURRENT_EXCEPTION_DESC(__VA_ARGS__); } }
192#ifdef RETURN_IF_FAILED
193 #undef RETURN_IF_FAILED
196#define RETURN_IF_FAILED(s) { try { tResult _errcode(s); if ( _errcode.IsFailed() ) { return ADTF_UCOM_ANNOTATE_RESULT(_errcode); } } catch (...) { RETURN_CURRENT_EXCEPTION(); } }
198#ifdef RETURN_IF_FAILED_DESC
199 #undef RETURN_IF_FAILED_DESC
202#define RETURN_IF_FAILED_DESC(s, ...) { try { tResult _errcode(s); if ( _errcode.IsFailed() ) { return ADTF_UCOM_COMPOSED_RESULT(_errcode, __VA_ARGS__); } } catch (...) { RETURN_CURRENT_EXCEPTION_DESC(__VA_ARGS__); } }
Copyright © Audi Electronics Venture GmbH.
char tChar
The tChar defines the type for platform character set (platform and compiler dependent type).
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
const tChar * GetFile() const noexcept
Get name of the file the error was reported in.
tErrorCode GetErrorCode() const noexcept
Get error code.
tInt32 GetLine() const noexcept
Get line in source file where the error was reported.
const tChar * GetFunction() const noexcept
Get name of the function the error was reported in.
const tChar * GetDescription() const noexcept
Get user provided error description.
Namespace for all functionality provided since v3.10.
std::string nested_exceptions_to_string(const std::exception &error)
Formats nested std::exceptions into a string, line by line.
tResult current_exception_to_result()
Converts the current exception object into a tResult.
std::string current_exception_to_string()
Trys to format the current exception into a string.
Namespace for the ADTF uCOM3 SDK.
Namespace for entire ADTF SDK.