From f4e89d58dade4113362b0341035ed742eeca6314 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 27 Aug 2021 16:53:35 +0200 Subject: QVERIFY_EXCEPTION_THROWN: re-throw unknown exceptions Swallowing unknown exceptions is dangerous business, as the exception might be a pthread cancellation token, the swallowing of which would terminate the program. Instead of returning from the catch-all-clause, therefore, re-throw the unknown exception. Fix tst_verifyexceptionthrown failure cases that use non-std::exception-derived true negative exceptions to not let the exception escape from the test function. As a drive-by, pretty up the macro's docs. [ChangeLog][QtTest][QVERIFY_EXCEPTION_THROWN] Now re-throws unknown exceptions (= not derived from std::exception) (was: swallowed them and returned from the test function), in order to play nice with pthread cancellation. Pick-to: 6.2 5.15 Change-Id: Ic036d4a9ed4b7683fa67e27af8bcbae0eefdd0da Reviewed-by: Qt CI Bot Reviewed-by: Edward Welbourne --- .../selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/auto/testlib/selftests') diff --git a/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp b/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp index c9365360de..e0e26a0a47 100644 --- a/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp +++ b/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp @@ -112,12 +112,16 @@ void tst_VerifyExceptionThrown::testCorrectMyExceptions() const void tst_VerifyExceptionThrown::testFailInt() const { - QVERIFY_EXCEPTION_THROWN(throw int(5), double); + try { + QVERIFY_EXCEPTION_THROWN(throw int(5), double); + } catch (int) {} } void tst_VerifyExceptionThrown::testFailStdString() const { - QVERIFY_EXCEPTION_THROWN(throw std::string("some string"), char*); + try { + QVERIFY_EXCEPTION_THROWN(throw std::string("some string"), char*); + } catch (const std::string &) {} } void tst_VerifyExceptionThrown::testFailStdRuntimeError() const -- cgit v1.2.3