Scope failure is not preventing application crush in case of uncaught exceptions
codephantom
me at noyb.com
Sun Dec 17 09:32:53 UTC 2017
On Sunday, 17 December 2017 at 08:26:03 UTC, Jonathan M Davis
wrote:
> assert(0) does indeed turn into a HLT instruction in -release
> mode (as does any assertion that's known to be false at compile
> time). It's a special case intended for marking code that's
> supposed to be unreachable. Without -release, failed assertions
> throw AssertErrors, so they're Errors not Exceptions, though I
> think that scope statements currently catch and then rethrow
> Throwable rather than Exception, which is why AssertErrors
> would be affected.
>
> - Jonathan M Davis
It's a little confusing, because Andrei's book says that
scope(failure) guarantees statement will be executed, if and only
if the current scope is exited by throwing an 'exception'.
One could *mistakingly* take that as meaning, throwing an object
rooted in the 'Exception' subclass of Throwable.
Of course assert actually throws an exception too, but it's a
special kind of exception rooted in the 'Error' subclass of
Throwable.
Perhaps, to be clearer, Andrei's book should have said:
scope(failure) guarantees statement will be executed, if and only
if the current scope is exited by throwing an object that
inherits from type Throwable. That would include, objects rooted
in the 'Exception' subclass, as well as objects rooted in 'Error'
subclass.
In which case, there's no bug in that code. It's doing what it's
meant to be doing.
More information about the Digitalmars-d-learn
mailing list