DefaultProtector.cpp 877 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <cppunit/Exception.h>
  2. #include <cppunit/extensions/TypeInfoHelper.h>
  3. #include "DefaultProtector.h"
  4. CPPUNIT_NS_BEGIN
  5. bool
  6. DefaultProtector::protect( const Functor &functor,
  7. const ProtectorContext &context )
  8. {
  9. try
  10. {
  11. return functor();
  12. }
  13. catch ( Exception &failure )
  14. {
  15. reportFailure( context, failure );
  16. }
  17. catch ( std::exception &e )
  18. {
  19. std::string shortDescription( "uncaught exception of type " );
  20. #if CPPUNIT_USE_TYPEINFO_NAME
  21. shortDescription += TypeInfoHelper::getClassName( typeid(e) );
  22. #else
  23. shortDescription += "std::exception (or derived).";
  24. #endif
  25. Message message( shortDescription, e.what() );
  26. reportError( context, message );
  27. }
  28. catch ( ... )
  29. {
  30. reportError( context,
  31. Message( "uncaught exception of unknown type") );
  32. }
  33. return false;
  34. }
  35. CPPUNIT_NS_END