lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] PATCH: Add undisplayable_exception not shown to user in report_exc


From: Vadim Zeitlin
Subject: [lmi] PATCH: Add undisplayable_exception not shown to user in report_exception().
Date: Sun, 24 Aug 2014 22:24:05 +0200

 Hello,

 Unfortunately I need to make another (small) modification to the common
LMI code to prevent the exceptions used to signal test failures from being
reported to the user (which is already bad as the tests are supposed to run
unattended) and then not being propagated to the test harness (which is
worse as the test is considered to have succeeded when, in fact, it failed).

 I hope the explanation in the commit message below is clear, but I'd like
to give an example of when this problem arise: currently, something
unexpected happens in the dialog shown when opening a GPT file. This
results in a wxWidgets assert failure and an exception being thrown from
the overridden OnAssertFailure() in the test application, but this
exception is caught, reported and then ignored by "catch(...)" in
gpt_view::OnCreate().

 I do have some doubts about whether the code in this particular function
is needed at all (in fact, I don't think so), but there are quite a few
other occurrences of "catch(...)" in the code and I'd like to ensure that
the same problem can't arise elsewhere. And by examining all these catch
clauses, I see that only a couple of them don't call report_exception() and
for them, the exception really does need to be ignored (e.g. to avoid
throwing from dtor), so by handling the new undisplayable_exception class
specially in report_exception() we ensure that this problem really can't
happen.

 Please let me know if you have any questions about this patch,
VZ

>From 148caed33e505f6cb3887b95f47d39a9023b7c97 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <address@hidden>
Date: Sun, 24 Aug 2014 22:13:54 +0200
Subject: Add undisplayable_exception not shown to user in report_exception().

This class provides a trapdoor allowing to subvert the usual exception
handling mechanism in special circumstances, e.g. during unattended testing,
when some exceptions must be recorded as test failures without user
intervention instead of being shown to the user and then ignored when
determining the final test result.

diff --git a/handle_exceptions.hpp b/handle_exceptions.hpp
index 2fa9e4b..0205281 100644
--- a/handle_exceptions.hpp
+++ b/handle_exceptions.hpp
@@ -30,6 +30,21 @@
 
 #include <cstdlib>   // std::exit()
 #include <exception>
+#include <stdexcept>
+
+/// Base class for the exceptions which should not be reported to the user.
+///
+/// Implicitly-declared special member functions do the right thing.
+
+class undisplayable_exception
+    :public std::runtime_error
+{
+  public:
+    explicit undisplayable_exception(std::string const& what)
+        :std::runtime_error(what)
+        {
+        }
+};
 
 /// This function, of type std::terminate_handler, is intended to be
 /// used as the argument of std::set_terminate().
@@ -67,6 +82,11 @@ inline void lmi_terminate_handler()
 ///  - the safe default action (throwing this exception) was accepted,
 /// in which case it's pointless to repeat the same message.
 ///
+/// Don't handle undisplayable_exception which is the base class for the
+/// exceptions which are not supposed to be ever shown to the user during the
+/// normal program execution -- nor even to arise in this case -- but which may
+/// be generated in special circumstances, e.g. in the testing build.
+///
 /// See
 //   http://article.gmane.org/gmane.comp.gnu.mingw.user/18355
 //     [2005-12-16T09:20:33Z from Greg Chicares]
@@ -85,6 +105,10 @@ inline void report_exception()
     catch(hobsons_choice_exception const&)
         {
         }
+    catch(undisplayable_exception const&)
+        {
+        throw;
+        }
     catch(std::exception const& e)
         {
         safely_show_message(e.what());
-- 
1.7.9

reply via email to

[Prev in Thread] Current Thread [Next in Thread]