Functions, nothrow and assert

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 8 08:14:40 PDT 2016


On Thu, Sep 08, 2016 at 12:07:43PM +0000, Lodovico Giaretta via Digitalmars-d-learn wrote:
[...]
> To expand on the previous correct answers, nothrow is about not
> throwing Exceptions. Exceptions are part of the normal flow of the
> program: they are used to signal recoverable errors, much like error
> codes.

Yes.


> Errors, on the other hand, are unrecoverable system failures that
> should not be catched (catching them is undefined behaviour, I think)
> and will surely lead to a crash. Errors are not covered by nothrow.
[...]

Yes.

Well, you *can* catch Errors, but the program may not be in a consistent
state, as dtors and such may not have been invoked, so what you can do
in the catch block should generally be limited to spitting out an error
message or writing to an error log (though it's arguable whether it's a
good idea to open files at this point!), then aborting the program ASAP.
It's probably a bad idea to write out data to data files, as the data
may be in a corrupted state at that point. Continuing after catching an
Error is Undefined Behaviour.


T

-- 
Those who don't understand Unix are condemned to reinvent it, poorly.


More information about the Digitalmars-d-learn mailing list