Assert and the optional Message

Timon Gehr timon.gehr at gmx.ch
Fri Mar 9 10:23:20 PST 2012


On 03/09/2012 05:56 PM, Jonathan M Davis wrote:
> The current implementation may not skip them, but if so, that might actually
> be a bug. Errors are not intended to be recoverable, so you can't rely on them
> hitting finally blocks, scope statements, or destructors. They may very well do
> so at present. While it's not guaranteed that they will, I'm not sure that
> it's guaranteed that they _won't_. So, it may or may not be a bug if they do.
>
> It was never intended that AssertError or any other Error be particularly
> catchable, but it's also true that D is a systems programming language, so
> it'll let you do stuff which is unsafe, so if you know what you're doing, then
> there are circumstances where you can get away with (unit testing is one
> example of where catching AssertErrors might make sense). But you have to know
> what you're doing, since it's _not_ safe.
>
> - Jonathan M Davis

AssertErrors must be recoverable because of the way contracts work.


More information about the Digitalmars-d-learn mailing list