Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-07-27 20:28:51 +0200
committerMartin Hořeňovský2025-07-27 21:41:02 +0200
commitd547cae549f484dda3c6a2b3cc5f71b9db40e842 (patch)
treefb947c6dd70b9eb5e8d7fd792bd85684b454d0fd /src/catch2
parentfee81626d2a4811095c3a39d20fb355eeb954101 (diff)
downloadcatch3-d547cae549f484dda3c6a2b3cc5f71b9db40e842.tar.gz
Fix bad error reporting for nested exceptions in default configuration
Bad handling of `TestFailureException` when translating unexpected exceptions inside assertion macros led to the unexpected exceptions handling erroring out through throwing the same exception again. This was then backstopped by the machinery for handling uncaught exceptions from assertions, which is normally used by the `CATCH_CONFIG_FAST_COMPILE` machinery, where we assume that it can only be invoked because the assertion macros are not configured to catch assertions. Closes #1292
Diffstat (limited to 'src/catch2')
-rw-r--r--src/catch2/benchmark/catch_benchmark.hpp4
-rw-r--r--src/catch2/internal/catch_exception_translator_registry.cpp4
2 files changed, 3 insertions, 5 deletions
diff --git a/src/catch2/benchmark/catch_benchmark.hpp b/src/catch2/benchmark/catch_benchmark.hpp
index eb688e7d..ce68aee7 100644
--- a/src/catch2/benchmark/catch_benchmark.hpp
+++ b/src/catch2/benchmark/catch_benchmark.hpp
@@ -86,9 +86,7 @@ namespace Catch {
auto analysis = Detail::analyse(*cfg, samples.data(), samples.data() + samples.size());
BenchmarkStats<> stats{ CATCH_MOVE(info), CATCH_MOVE(analysis.samples), analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
getResultCapture().benchmarkEnded(stats);
- } CATCH_CATCH_ANON (TestFailureException const&) {
- getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr);
- } CATCH_CATCH_ALL{
+ } CATCH_CATCH_ALL {
getResultCapture().benchmarkFailed(translateActiveException());
// We let the exception go further up so that the
// test case is marked as failed.
diff --git a/src/catch2/internal/catch_exception_translator_registry.cpp b/src/catch2/internal/catch_exception_translator_registry.cpp
index 1eb61147..8867d78b 100644
--- a/src/catch2/internal/catch_exception_translator_registry.cpp
+++ b/src/catch2/internal/catch_exception_translator_registry.cpp
@@ -59,10 +59,10 @@ namespace Catch {
// To avoid having to handle TFE explicitly everywhere, we just
// rethrow it so that it goes back up the caller.
catch( TestFailureException& ) {
- std::rethrow_exception(std::current_exception());
+ return "{ nested assertion failed }";
}
catch( TestSkipException& ) {
- std::rethrow_exception(std::current_exception());
+ return "{ nested SKIP() called }";
}
catch( std::exception const& ex ) {
return ex.what();