On Saturday, 12 March 2016 21:12:00 UTC+2, Mr Flibble wrote:
Leigh, can you please check why your posts appear twice in comp.lang.c++?
> On 09/03/2016 14:25, James K. Lowden wrote:
> >
> > On Tue, 8 Mar 2016 06:31:12 CST
> > Mr Flibble <
flibbleREM...@i42.co.uk> wrote:
> >
> >> As it currently stands a more serious std::logic_error exception can
> >> be downgraded into a less serious std::runtime_error exception if an
> >> exception is thrown whilst evaluating the throw expression.
> >
> > Could you be more specific, please? logic_error is mentioned in my
> > copy of the C++ only in section 19.2.1 (per the index), and I don't
> > find any mention of "downgrading". I also don't understand how it
> > *could* happen, since the compiler generates exception-handling
> > instructions, and the language per se doesn't define logic_error.
>
> Typically when constructing an exception derived from std::logic_error a
> std::string object is created for the exception message which can cause
> std::bad_alloc (a std::runtime_error exception) to be thrown replacing
> the originally intended exception.
That is indeed so, but 'bad_alloc' is also typically unrecoverable
fatal and on border of 'logic_error'. It can be that platform was picked
that is incapable of handling the task under hand or input was accepted
that is outside of capabilities of platform or software is leaking
resources so it will run out sooner or later. The reason why it is
'runtime_error' is perhaps because the system might be ran out of
resources because of some other software did exhaust the available
memory. Also that situation is not recoverable by software on its own.
>
> >
> > Why do you say logic_error is "more serious" than runtime_error?
> > Semantically that's not true, insofar as seriousness is not defined
> > by the library. I guess you mean that -- assuming they're used as
> > intended -- a logic error could have been avoided by the programmer,
> > whereas a runtime error could not. Depending on the situation, though,
> > either one can leave the user high and dry.
>
> In general std::logic_error is more serious then std::runtime_error
> because you can often recover from a std::runtime_error but a
> std::logic_error exception is often a sign that something is seriously
> screwed and the only safe course of action is to terminate the process.
> I treat std::logic_error based exceptions as fatal conditions because
> of this.
Yes but if you threat 'bad_alloc' as 'logic_error' too then no harm done?