lmi
[Top][All Lists]
Advanced

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

Re: [lmi] [PATCH] Add undisplayable_exception


From: Vadim Zeitlin
Subject: Re: [lmi] [PATCH] Add undisplayable_exception
Date: Thu, 9 Oct 2014 16:40:55 +0200

On Thu, 09 Oct 2014 13:57:52 +0000 Greg Chicares <address@hidden> wrote:

GC> > GC> Excellent idea. Let's do it that way, keeping the production system
GC> > GC> unchanged.
GC> 
GC> I intended my comment (the last two lines quoted above) to apply to
GC> option BLUE, which can keep production 100% unchanged.

 Sorry, I don't see how is it possible to keep the production code 100%
unchanged with neither option, but in particular with the option BLUE.

GC> Will you also move the declaration of class undisplayable_exception
GC> to the testing code (e.g., to some header included only in that code),
GC> so that even its declaration is unknown to the production system?
GC> Then production is indeed "100% unchanged".

 I might be missing something here, but the class declaration must be
available to report_exception() in handle_exceptions.hpp, which is part of
production code, in order to allow catching the exceptions of this type.

 So the best I can do is the patch below, please let me know if you see a
way of improving it, i.e. minimizing the changes to the production version
even further. Notice that I did test that doing this:

diff --git a/skeleton.cpp b/skeleton.cpp
index 19fa351..62d917c 100644
--- a/skeleton.cpp
+++ b/skeleton.cpp
@@ -894,6 +894,7 @@ void Skeleton::UponTestAppFatal(wxCommandEvent&)

 void Skeleton::UponTestAppStandardException(wxCommandEvent&)
 {
+    throw wx_test_exception("UNDISPLAYABLE");
     throw std::runtime_error("Test a standard exception.");
 }

did result in linking error now (i.e. with the patch below), which, while
not as good as compilation error, should still prevent any honest mistakes.

 But, again, please let me know if you see some way to make it work without
exposing wx_test_exception at all, I just don't see it.

 Thanks,
VZ

-- >8 --
commit a69298db3aeafa554367ee7872dd19883aaa56f8
Author: Vadim Zeitlin <address@hidden>
Date:   Sun Aug 24 22:13:54 2014 +0200

    Add wx_test_exception not shown to user in report_exception().
    
    This class provides a trapdoor allowing to subvert the usual exception
    handling mechanism in the testing build, 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.
    
    It doesn't affect the normal production build at all and, in fact, can't 
even
    be created in it, as its constructor is intentionally not implemented in it.

diff --git a/handle_exceptions.hpp b/handle_exceptions.hpp
index 2fa9e4b..03c653a 100644
--- a/handle_exceptions.hpp
+++ b/handle_exceptions.hpp
@@ -30,6 +30,25 @@
 
 #include <cstdlib>   // std::exit()
 #include <exception>
+#include <stdexcept>
+
+/// Base class for the exceptions which should not be reported to the user
+/// because they are only used during testing and are ultimately caught by the
+/// testing harness.
+///
+/// Objects of wx_test_exception class cannot be even created in the main
+/// executable as its constructor is intentionally not implemented there, it is
+/// provided only by the testing executable which is also the only place where
+/// the test exceptions are thrown.
+///
+/// Implicitly-declared special member functions do the right thing.
+
+class wx_test_exception
+    :public std::runtime_error
+{
+  public:
+    explicit wx_test_exception(std::string const& what);
+};
 
 /// This function, of type std::terminate_handler, is intended to be
 /// used as the argument of std::set_terminate().
@@ -67,6 +86,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 wx_test_exception which must be allowed to propagate upwards
+/// to be caught, and analyzed, by the testing harness when building the
+/// testing executable. In the normal production executable, objects of this
+/// type can never be created nor thrown.
+///
 /// See
 //   http://article.gmane.org/gmane.comp.gnu.mingw.user/18355
 //     [2005-12-16T09:20:33Z from Greg Chicares]
@@ -85,6 +109,10 @@ inline void report_exception()
     catch(hobsons_choice_exception const&)
         {
         }
+    catch(wx_test_exception const&)
+        {
+        throw;
+        }
     catch(std::exception const& e)
         {
         safely_show_message(e.what());

reply via email to

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