[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d4f71df 2/3: Suppress misleading errors when
[lmi-commits] [lmi] master d4f71df 2/3: Suppress misleading errors when generating too many PDF pages
Sun, 4 Feb 2018 08:51:59 -0500 (EST)
Author: Vadim Zeitlin <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Suppress misleading errors when generating too many PDF pages
The warning about not generating enough pages was also given,
confusingly, when too many of them were generated because the
destructors of the remaining pages were executed as part of stack
unwinding after the failure of the check in next_page() for a previous
Fix this by only giving the warning about "missing extra pages" when the
object is destroyed normally. This fixes the problem described above,
but also makes sense more generally as we don't want to warn about
missing extra pages if the PDF generation failed because of any other
error anyhow, as this is normal and expected in this case, and the
warning just detracts from the real error.
ledger_pdf_generator_wx.cpp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/ledger_pdf_generator_wx.cpp b/ledger_pdf_generator_wx.cpp
index 48d3b15..729ca12 100644
@@ -50,6 +50,7 @@
#include <cstddef> // size_t
#include <cstdint> // SIZE_MAX
#include <cstdlib> // strtoul()
+#include <exception> // uncaught_exceptions()
#include <memory> // make_unique(), shared_ptr,
@@ -1191,10 +1192,13 @@ class numbered_page : public page_with_footer
- // Check that next_page() was called the expected number of times.
- // Unfortunately we can't use LMI_ASSERT() in the (noexcept) dtor, so
- // use warning() instead.
+ // Check that next_page() was called the expected number of times,
+ // unless we're unwinding the stack due to some other error, in which
+ // case it is normal that extra pages haven't been generated.
+ // Notice that we shouldn't use LMI_ASSERT() in the dtor by default,
+ // and it's better to use warning() instead of using noexcept(false).
+ if(extra_pages_ && !std::uncaught_exceptions())
<< "Logic error: "