libsigc++: exception_catch()

libsigc++ 2.10.3

exception_catch()
Adaptors

sigc::exception_catch() catches an exception thrown from within the wrapped functor and directs it to a catcher functor. This catcher can then rethrow the exception and catch it with the proper type. More...

sigc::exception_catch() catches an exception thrown from within the wrapped functor and directs it to a catcher functor. This catcher can then rethrow the exception and catch it with the proper type.

Note that the catcher is expected to return the same type as the wrapped functor so that normal flow can continue.

Catchers can be cascaded to catch multiple types, because uncaught rethrown exceptions proceed to the next catcher adaptor.

Examples:
  struct my_catch
  {
  int operator()()
  {
  try { throw; }
  catch (std::range_error e) // catch what types we know
  { std::cerr << "caught " << e.what() << std::endl; }
  return 1;
  }
  }
  int foo(); // throws std::range_error
  sigc::exception_catch(&foo, my_catch())();

The functor sigc::exception_catch() returns can be directly passed into sigc::signal::connect().

Example:
  sigc::signal<int> some_signal;
  some_signal.connect(sigc::exception_catch(&foo, my_catch));

sigc::signal
Convenience wrapper for the numbered sigc::signal# templates.
Definition: signal.h:4013
std::range_error
std::cerr
ostream cerr
sigc::exception_catch
exception_catch_functor< T_functor, T_catcher > exception_catch(const T_functor &_A_func, const T_catcher &_A_catcher)
Definition: exception_catch.h:326
std::endl
basic_ostream< _CharT, _Traits > & endl(basic_ostream< _CharT, _Traits > &__os)
std::range_error::what
virtual const char * what() const _GLIBCXX_TXN_SAFE_DYN noexcept
sigc::signal7< T_return, nil, nil, nil, nil, nil, nil, nil, nil >::connect
iterator connect(const slot_type &slot_)
Add a slot to the list of slots.
Definition: signal.h:3871