[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master d4f71df 2/3: Suppress misleading errors when
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master d4f71df 2/3: Suppress misleading errors when generating too many PDF pages |
Date: |
Sun, 4 Feb 2018 08:51:59 -0500 (EST) |
branch: master
commit d4f71df0334b2302afa6409c597b6c6cc93c25e5
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
page.
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
--- a/ledger_pdf_generator_wx.cpp
+++ b/ledger_pdf_generator_wx.cpp
@@ -50,6 +50,7 @@
#include <cstddef> // size_t
#include <cstdint> // SIZE_MAX
#include <cstdlib> // strtoul()
+#include <exception> // uncaught_exceptions()
#include <fstream>
#include <map>
#include <memory> // make_unique(), shared_ptr,
unique_ptr
@@ -1191,10 +1192,13 @@ class numbered_page : public page_with_footer
~numbered_page() override
{
- // 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.
- if(extra_pages_)
+ // 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())
{
warning()
<< "Logic error: "