[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] [PATCH] Add undisplayable_exception
From: |
Vadim Zeitlin |
Subject: |
[lmi] [PATCH] Add undisplayable_exception |
Date: |
Mon, 6 Oct 2014 20:08:43 +0200 |
Hello again,
This is the last patch on which the testing changes depend. I expect it
might be a bit more controversial than the previous ones as it's not really
clear why should there be a special case for this "undisplayable_exception".
And, indeed, during the normal program execution this isn't needed. However
the GUI tests suite depends on being able to catch the exceptions thrown
when a test fails and this wouldn't work if the normal GUI code caught
these exceptions and displayed them to the user and adding a special class
for the sole purpose of allowing to handle it specifically inside
report_exception() is the simplest possibility to do it that I see.
The patch itself should explain show more clearly how it works:
-- >8 --
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());
-- >8 --
Possible improvement could consist in choosing an appropriately eldritch
name instead of the current banally descriptive "undisplayable_exception",
but my knowledge of Lovecraftian lore is insufficient to know what would be
most appropriate for a unit testing related class (and has Lovecraft really
plumbed such depths of horror to touch unit testing?).
Please let me know what do you think about this patch, TIA!
VZ
- [lmi] [PATCH] Add undisplayable_exception,
Vadim Zeitlin <=
- Re: [lmi] [PATCH] Add undisplayable_exception, Greg Chicares, 2014/10/08
- Re: [lmi] [PATCH] Add undisplayable_exception, Vadim Zeitlin, 2014/10/08
- Re: [lmi] [PATCH] Add undisplayable_exception, Greg Chicares, 2014/10/09
- Re: [lmi] [PATCH] Add undisplayable_exception, Vadim Zeitlin, 2014/10/09
- Re: [lmi] [PATCH] Add undisplayable_exception, Greg Chicares, 2014/10/09
- Re: [lmi] [PATCH] Add undisplayable_exception, Vadim Zeitlin, 2014/10/09
- Re: [lmi] [PATCH] Add undisplayable_exception, Greg Chicares, 2014/10/09
- Re: [lmi] [PATCH] Add undisplayable_exception, Greg Chicares, 2014/10/09
- Re: [lmi] [PATCH] Add undisplayable_exception, Vadim Zeitlin, 2014/10/09
- Re: [lmi] [PATCH] Add undisplayable_exception, Greg Chicares, 2014/10/11