[Issue 11461] `Error`s are not thrown as `pure nothrow` functions are optimized out with "-O -release"

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 15 11:53:10 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11461



--- Comment #9 from monarchdodra at gmail.com 2013-11-15 11:53:06 PST ---
(In reply to comment #8)
> Hi, guys.
> Maybe i'm too stupid, but how nothrow function can throw ?

D defines both "Exception" and "Error", which derive from "Throwable".
"Exception", is what you know from C++: The standard thing that gets thrown
around to notify things like database/io problems: Things that "happen" and
need to be dealt with. They unwind the stack, destroy things on the stack,
etc...

"Error" is an entire other beast: They are C++'s "assert" in more powerful:
They represent a critical error of the program state: corruption, out of
memory, failed assertions. They represent something you *cannot* recover from,
and are telling you the program needs to halt.

Unlike an "Exception", "Error" will blast through the call stack, bypassing
destructors, bypassing "nothrow" function, bypassing "catch(Exception)"... They
are not meant to happen general, and shouldn't be "handled" in the general
sense of the term.

So long story short, an Error can be thrown from a nothrow function, because an
Error doesn't trigger stack cleanup, which means there is no need to generate
_Exceptio_ handling code".

=> "nothrow" means "will not throw _Exceptions_".

I'd link some references, but the best I know of is TDPL.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list