16 void PrintNestedException(std::ostream& os,
const std::nested_exception& e,
unsigned level = 0);
18 void PrintNestedException(std::ostream& os,
const std::exception& e,
unsigned level = 0) {
19 os <<
'[' << level <<
"]: " << e.what() <<
"\n";
21 std::rethrow_if_nested(e);
22 }
catch (
const std::exception& nested) {
23 PrintNestedException(os, nested, level + 1);
24 }
catch (std::nested_exception
const& nested) {
25 PrintNestedException(os, nested, level + 1);
27 os << std::string(level + 1,
' ') <<
"unknown error\n";
31 void PrintNestedException(std::ostream& os,
const std::nested_exception& e,
unsigned level) {
36 }
catch (
const std::exception& e) {
37 PrintNestedException(os, e, level + 1);
38 }
catch (std::nested_exception
const& e) {
39 PrintNestedException(os, e, level + 1);
41 os << std::string(level + 1,
' ') <<
"unknown error\n";
47 PrintNestedException(os, e);
52 auto ptr = std::current_exception();
54 std::rethrow_exception(std::move(ptr));
56 }
catch (std::exception
const& e) {
57 PrintNestedException(os, e);
58 }
catch (std::nested_exception
const& e) {
59 PrintNestedException(os, e);
61 os <<
"unknown error";
68 std::rethrow_exception(std::move(ptr));
70 }
catch (std::exception
const& e) {
71 PrintNestedException(os, e);
72 }
catch (std::nested_exception
const& e) {
73 PrintNestedException(os, e);
75 os <<
"unknown error";
82 std::rethrow_exception(std::move(ptr));
84 }
catch (std::exception
const& e) {
87 os <<
"unknown error";
std::string Str() const
Convenience function for constructing a std::string from the exception.
void ReportNestedExceptions(std::ostream &os) noexcept
void FormatException(std::ostream &os, std::exception_ptr ptr)
Report without nesting.