cppx-core
exception-unwrapping.hpp
Go to the documentation of this file.
1 #pragma once // Source encoding: UTF-8 with BOM (π is a lowercase Greek "pi").
2 
3 #include <cppx-core/collections/is_empty.hpp> // cppx::is_empty
4 #include <cppx-core/language/syntax/macro-use.hpp> // CPPX_USE_STD
5 #include <cppx-core/language/types/C_str_.hpp> // cppx::C_str
6 
7 #include <exception> // std::(exception, rethrow_exception)
8 #include <functional> // std::function
9 #include <utility> // std::move
10 
11 namespace cppx
12 {
13  CPPX_USE_STD( exception, function, move, rethrow_if_nested, string );
14 
16  const exception& x,
17  const function<void( const C_str )>& f
18  )
19  {
20  f( x.what() );
21  try
22  {
23  rethrow_if_nested( x );
24  }
25  catch( const exception& rx )
26  {
28  }
29  catch( ... )
30  {
31  f( "<a non-standard exception>" );
32  }
33  }
34 
35  inline auto description_lines_from( const exception& x )
36  -> string
37  {
38  string result;
39  const auto add = [&]( const C_str s ) -> void
40  {
41  if( not is_empty( result ) )
42  {
43  result += '\n';
44  }
45  result += s;
46  };
48  return result;
49  }
50 
51 } // namespace cppx
void call_with_description_lines_from(const exception &x, const function< void(const C_str)> &f)
C_str for char const*; Wide_c_str for wchar_t const*; and Mutable_c_str and Mutable_wide_c_str as dit...
CPPX_USE_STD(basic_string, basic_string_view, bitset, char_traits, size)
auto is_empty(const Collection &c) -> Truth
Definition: is_empty.hpp:33
auto description_lines_from(const exception &x) -> string
C_str_< char > C_str
Definition: C_str_.hpp:38
Macros for generating more concise and clear using statements, primarily $use_cppx and $use_std,...