lmi
[Top][All Lists]
Advanced

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

Re: [lmi] PATCH: use std::uncaught_exceptions()


From: Vadim Zeitlin
Subject: Re: [lmi] PATCH: use std::uncaught_exceptions()
Date: Sat, 24 Mar 2018 23:34:22 +0100

On Sat, 24 Mar 2018 21:19:34 +0000 Greg Chicares <address@hidden> wrote:

GC> Examining every use case in lmi:
GC>   vim -p $(grep --files-with-match uncaught_exception *.?pp)
GC> I see no rollback semantics--not surprising because we have no "undo".

 It's not exactly "undo", but wx_test_document_base dtor uses it in a
rather similar way, and only closes the window (undoing opening it in ctor)
during unwinding. Although it arguably could close the window in any case,
but keeping the window opened when there is no active exception is nice
because it allows to immediately see which window we forgot to close.

GC> The only other use is in 'ledger_pdf_generator_wx.cpp', and I'm
GC> not sure it does exactly what we want there:
GC> 
GC>     ~numbered_page() override
GC>     {
GC>         // Check that next_page() was called the expected number of times,
GC>         // unless we're unwinding the stack due to some other error, in 
which
GC>         // case it is normal that extra pages haven't been generated.
GC>         //
GC>         // Notice that we shouldn't use LMI_ASSERT() in the dtor by default,
GC>         // and it's better to use warning() instead of using 
noexcept(false).
GC>         if(extra_pages_ && !std::uncaught_exceptions())
GC>             {
GC>             warning()
GC> 
GC> If an exception has been thrown, then of course we don't need to
GC> warn that it prevented PDF generation from completing. However,
GC> if the page count is wrong but no exception has been thrown,
GC> then I'd say that a crucial postcondition has been violated, and
GC> displaying a warning message doesn't seem severe enough: I'd
GC> rather delete the PDF file in that case, or, much better, prevent
GC> it (or even any fragment of it) from being written to disk. That's
GC> lmi's sine qua non: never write an invalid PDF file, because ours
GC> is a heavily regulated industry (and page numbering actually is
GC> prescribed by regulation). How should we implement that?
GC>  - throw in the dtor when not unwinding, even though that goes
GC>    against accepted pre-C++17 wisdom?

 I guess we should indeed use LMI_ASSERT() and throw from the dtor. It also
seems that we need to delete the PDF output file, if it exists, if an
exception was thrown. I'm not sure if this should be done in
write_ledger_as_pdf() itself or if it might make sense to do this in
ledger_emitter::emit_cell(), for all file types instead?

 What do you think would be better?
VZ


reply via email to

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