// g++ -Wall -std=c++11 example_handler.cpp
#include <string>
#include <iostream>

struct Exception1 { };
struct Exception2 { };

template<typename F>
void errHandler(F f, bool enabled)
{
  if(!enabled)
    return;
  try
  {
    f();
  }
  catch(Exception1 const&)
  {
    // bla bla
  }
  catch(Exception2 const&)
  {
    // bla bla
  }
}


struct Example
{
  void f1(std::string& str) const
  {
    auto l = [&](){ str+="?"; };
    errHandler(l, enabled_);
  }

  void f2(std::string& str) const
  {
    auto l = [&](){ str+="!"; };
    errHandler(l, enabled_);
  }

  bool enabled_ = true;
};


int main(void)
{
  const Example e;
  std::string   str("what");
  std::cout << str << std::endl;
  e.f1(str);
  std::cout << str << std::endl;
  e.f2(str);
  std::cout << str << std::endl;
  return 0;
}
