26 inline 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 =
"")
57 const auto strAnnotatedDescription = adtf::util::cString::Format(
"%s [%s:%d(%s)]\n%s",
58 strOriginalDescription,
59 adtf::util::cFilename(oOriginal.
GetFile()).GetName().GetPtr(),
65 strAnnotatedDescription,
67 adtf::util::cFilename(strFile).GetName().GetPtr(),
73 auto exception = std::current_exception();
78 std::rethrow_exception(exception);
81 catch(
const std::exception& error)
85 static_cast<int32_t
>(line),
86 adtf::util::cFilename(file).GetName(),
91 return annotate_result(oError, file,
static_cast<int32_t
>(line),
function);
97 static_cast<int32_t
>(line),
116 std::ostringstream stream;
117 detail::format_nested_exception(error, stream);
128 auto exception = std::current_exception();
133 std::rethrow_exception(exception);
136 catch(
const std::exception& error)
146 return "unknown exception";
172 #define ADTF_UCOM_ANNOTATE_RESULT(_result) adtf::ucom::kiwi::detail::annotate_result(_result, __FILE__, __LINE__, __FUNC__)
175 #define ADTF_UCOM_COMPOSED_RESULT(_result, ...) adtf::ucom::kiwi::detail::annotate_result(_result, __FILE__, __LINE__, __FUNC__, adtf::util::cString::Format(__VA_ARGS__).GetPtr())
178 #define THROW_ERROR_DESC(_code, ...) throw DETAILED_RESULT(_code, __VA_ARGS__)
180 #define THROW_IF_FAILED(s) { tResult _errcode(s); if ( _errcode.IsFailed() ) { throw ADTF_UCOM_ANNOTATE_RESULT(_errcode); } }
182 #define THROW_IF_FAILED_DESC(s, ...) { tResult _errcode(s); if ( _errcode.IsFailed() ) { throw ADTF_UCOM_COMPOSED_RESULT(_errcode, __VA_ARGS__); } }
185 #define RETURN_CURRENT_EXCEPTION() return adtf::ucom::kiwi::detail::current_exception_to_result(__FILE__, __LINE__, __FUNC__)
187 #define RETURN_CURRENT_EXCEPTION_DESC(...) return ADTF_UCOM_COMPOSED_RESULT(adtf::ucom::kiwi::detail::current_exception_to_result(__FILE__, __LINE__, __FUNC__), __VA_ARGS__)
190 #define RETURN_IF_THROWS(s) { try { (s); } catch(...) { RETURN_CURRENT_EXCEPTION(); } }
192 #define RETURN_IF_THROWS_DESC(s, ...) { try { (s); } catch(...) { RETURN_CURRENT_EXCEPTION_DESC(__VA_ARGS__); } }
195 #ifdef RETURN_IF_FAILED
196 #undef RETURN_IF_FAILED
199 #define RETURN_IF_FAILED(s) { try { tResult _errcode(s); if ( _errcode.IsFailed() ) { return ADTF_UCOM_ANNOTATE_RESULT(_errcode); } } catch (...) { RETURN_CURRENT_EXCEPTION(); } }
201 #ifdef RETURN_IF_FAILED_DESC
202 #undef RETURN_IF_FAILED_DESC
205 #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.
A common result class usable as return value throughout.
const tChar * GetDescription() const
Get user provided error description.
tInt32 GetLine() const
Get line in source file where the error was reported.
tErrorCode GetErrorCode() const
Get error code.
const tChar * GetFunction() const
Get name of the function the error was reported in.
const tChar * GetFile() const
Get name of the file the error was reported in.
const tChar * GetPtr() const
This function returns the current string as an array of characters (c-style)
cString to_string(const tResult &i_oResult, eResultFormatFlags i_eFormatFlags=eResultFormatFlags::RFF_DisableNone, const tChar *i_strFormat=nullptr)
Copy all information of an assigned result object to a (formatted) string.
tResult current_exception_to_result()
Converts the current exception object into a tResult.
std::string nested_exceptions_to_string(const std::exception &error)
Formats nested std::exceptions into a string, line by line.
std::string current_exception_to_string()
Trys to format the current exception into a string.
Namespace for entire ADTF SDK.