| 3933 | // Result in case of an SEH exception. |
| 3934 | template <class T, typename Result> |
| 3935 | Result HandleExceptionsInMethodIfSupported( |
| 3936 | T* object, Result (T::*method)(), const char* location) { |
| 3937 | // NOTE: The user code can affect the way in which Google Test handles |
| 3938 | // exceptions by setting GTEST_FLAG(catch_exceptions), but only before |
| 3939 | // RUN_ALL_TESTS() starts. It is technically possible to check the flag |
| 3940 | // after the exception is caught and either report or re-throw the |
| 3941 | // exception based on the flag's value: |
| 3942 | // |
| 3943 | // try { |
| 3944 | // // Perform the test method. |
| 3945 | // } catch (...) { |
| 3946 | // if (GTEST_FLAG(catch_exceptions)) |
| 3947 | // // Report the exception as failure. |
| 3948 | // else |
| 3949 | // throw; // Re-throws the original exception. |
| 3950 | // } |
| 3951 | // |
| 3952 | // However, the purpose of this flag is to allow the program to drop into |
| 3953 | // the debugger when the exception is thrown. On most platforms, once the |
| 3954 | // control enters the catch block, the exception origin information is |
| 3955 | // lost and the debugger will stop the program at the point of the |
| 3956 | // re-throw in this function -- instead of at the point of the original |
| 3957 | // throw statement in the code under test. For this reason, we perform |
| 3958 | // the check early, sacrificing the ability to affect Google Test's |
| 3959 | // exception handling in the method where the exception is thrown. |
| 3960 | if (internal::GetUnitTestImpl()->catch_exceptions()) { |
| 3961 | #if GTEST_HAS_EXCEPTIONS |
| 3962 | try { |
| 3963 | return HandleSehExceptionsInMethodIfSupported(object, method, location); |
| 3964 | } catch (const AssertionException&) { // NOLINT |
| 3965 | // This failure was reported already. |
| 3966 | } catch (const internal::GoogleTestFailureException&) { // NOLINT |
| 3967 | // This exception type can only be thrown by a failed Google |
| 3968 | // Test assertion with the intention of letting another testing |
| 3969 | // framework catch it. Therefore we just re-throw it. |
| 3970 | throw; |
| 3971 | } catch (const std::exception& e) { // NOLINT |
| 3972 | internal::ReportFailureInUnknownLocation( |
| 3973 | TestPartResult::kFatalFailure, |
| 3974 | FormatCxxExceptionMessage(e.what(), location)); |
| 3975 | } catch (...) { // NOLINT |
| 3976 | internal::ReportFailureInUnknownLocation( |
| 3977 | TestPartResult::kFatalFailure, |
| 3978 | FormatCxxExceptionMessage(nullptr, location)); |
| 3979 | } |
| 3980 | return static_cast<Result>(0); |
| 3981 | #else |
| 3982 | return HandleSehExceptionsInMethodIfSupported(object, method, location); |
| 3983 | #endif // GTEST_HAS_EXCEPTIONS |
| 3984 | } else { |
| 3985 | return (object->*method)(); |
| 3986 | } |
| 3987 | } |
| 3988 | |
| 3989 | } // namespace internal |
| 3990 |
no test coverage detected