exception: Add exception_msg helper
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
4c499f2905
commit
be273d4263
@ -39,7 +39,7 @@ int main(int, const char *[])
|
||||
return 0;
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << ex.what() << " FAIL\n";
|
||||
std::cerr << stdex::exception_msg(ex) << " FAIL\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +23,21 @@ namespace stdex
|
||||
///
|
||||
user_cancelled(_In_opt_z_ const char* msg = "operation cancelled") : runtime_error(msg) {}
|
||||
};
|
||||
|
||||
///
|
||||
/// Concatenates error messages when exception is nested.
|
||||
///
|
||||
/// \param ex Exception
|
||||
///
|
||||
/// \returns Concatenated exception messages with ": " delimiter.
|
||||
///
|
||||
inline std::string exception_msg(const std::exception& ex)
|
||||
{
|
||||
try { std::rethrow_if_nested(ex); }
|
||||
catch (const std::exception& nested_ex) {
|
||||
return std::string(ex.what()) + ": " + exception_msg(nested_ex);
|
||||
}
|
||||
catch (...) {}
|
||||
return ex.what();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user