// Runs the test and updates the test result.
void Test::Run() {
if (!HasSameFixtureClass()) return;
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
impl->os_stack_trace_getter()->UponLeavingGTest();
try {
SetUp();
} catch(const std::exception& ex) {
AddExceptionThrownFailure(ex.what(), "SetUp()");
} catch(...) { // this might need windows-specific code to NOT catch run-time errors.
AddExceptionThrownFailure("unknown exception", "SetUp()");
}
// We will run the test only if SetUp() had no fatal failure.
if (!HasFatalFailure()) {
impl->os_stack_trace_getter()->UponLeavingGTest();
try {
TestBody();
} catch(const std::exception& ex) {
AddExceptionThrownFailure(ex.what(), "the test body");
} catch(...) {
AddExceptionThrownFailure("unknown exception", "the test body");
}
}
// However, we want to clean up as much as possible. Hence we will
// always call TearDown(), even if SetUp() or the test body has
// failed.
impl->os_stack_trace_getter()->UponLeavingGTest();
try {
TearDown();
} catch(const std::exception& ex) {
AddExceptionThrownFailure(ex.what(), "TearDown()");
} catch(...) {
AddExceptionThrownFailure("unknown exception", "TearDown()");
}
}
// AddExceptionThrownFailure altered as well.
I like to catch c++ exceptions and treat them as test failures, continuing to run other tests, but NOT catch runtime errors (like illegal memory access) -- I want the debugger to catch those.
So I currently have some code like the following (for all platforms, not just windows). I can rewrite this to only do try/catch based off of GTEST_FLAG(catch_exceptions) and submit a patch, but that flag seems to be used for windows-runtime-errors rather than what I want.Would we want a new flag? Is anyone interested in a patch like this?