MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / HandleExceptionsInMethodIfSupported

Function HandleExceptionsInMethodIfSupported

tests/gtest/src/gtest.cc:2615–2667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2613// Result in case of an SEH exception.
2614template <class T, typename Result>
2615Result HandleExceptionsInMethodIfSupported(
2616 T* object, Result (T::*method)(), const char* location) {
2617 // NOTE: The user code can affect the way in which Google Test handles
2618 // exceptions by setting GTEST_FLAG(catch_exceptions), but only before
2619 // RUN_ALL_TESTS() starts. It is technically possible to check the flag
2620 // after the exception is caught and either report or re-throw the
2621 // exception based on the flag's value:
2622 //
2623 // try {
2624 // // Perform the test method.
2625 // } catch (...) {
2626 // if (GTEST_FLAG(catch_exceptions))
2627 // // Report the exception as failure.
2628 // else
2629 // throw; // Re-throws the original exception.
2630 // }
2631 //
2632 // However, the purpose of this flag is to allow the program to drop into
2633 // the debugger when the exception is thrown. On most platforms, once the
2634 // control enters the catch block, the exception origin information is
2635 // lost and the debugger will stop the program at the point of the
2636 // re-throw in this function -- instead of at the point of the original
2637 // throw statement in the code under test. For this reason, we perform
2638 // the check early, sacrificing the ability to affect Google Test's
2639 // exception handling in the method where the exception is thrown.
2640 if (internal::GetUnitTestImpl()->catch_exceptions()) {
2641#if GTEST_HAS_EXCEPTIONS
2642 try {
2643 return HandleSehExceptionsInMethodIfSupported(object, method, location);
2644 } catch (const AssertionException&) { // NOLINT
2645 // This failure was reported already.
2646 } catch (const internal::GoogleTestFailureException&) { // NOLINT
2647 // This exception type can only be thrown by a failed Google
2648 // Test assertion with the intention of letting another testing
2649 // framework catch it. Therefore we just re-throw it.
2650 throw;
2651 } catch (const std::exception& e) { // NOLINT
2652 internal::ReportFailureInUnknownLocation(
2653 TestPartResult::kFatalFailure,
2654 FormatCxxExceptionMessage(e.what(), location));
2655 } catch (...) { // NOLINT
2656 internal::ReportFailureInUnknownLocation(
2657 TestPartResult::kFatalFailure,
2658 FormatCxxExceptionMessage(nullptr, location));
2659 }
2660 return static_cast<Result>(0);
2661#else
2662 return HandleSehExceptionsInMethodIfSupported(object, method, location);
2663#endif // GTEST_HAS_EXCEPTIONS
2664 } else {
2665 return (object->*method)();
2666 }
2667}
2668
2669} // namespace internal
2670

Callers 1

RunMethod · 0.70

Calls 5

GetUnitTestImplFunction · 0.70
whatMethod · 0.45

Tested by

no test coverage detected