Assert and the optional Message

Jacob Carlborg doob at me.com
Sat Mar 10 08:03:43 PST 2012


On 2012-03-09 20:06, Jonathan M Davis wrote:

> In what way? Yes, they're _catchable_, but everything that was on the unwound
> portion of the stack is now in an undefined state. So, recovering from the
> AssertError and continuing execution doesn't work. So, a handler can catch the
> AssertError and do something before letting it kill the program, but portions
> of the program are definitely in an undefined state when an AssertError is
> caught. The closer the catch point is to the throw point, the less of an issue
> that is, but unless you can guarantee that no destructors, scope statements,
> or finally blocks were between the throw point and the catch point, then some
> portion of the program is in an undefined state, and continuing program
> execution is a bad idea. It _is_ possible to catch an AssertError, but you
> have to be very careful about what you do after that.
>
> I'm not aware of anything in contracts which would involve catching an
> AssertError and then continuing execution. When a contract fails, it's going
> to kill the program just like any other assertion failure does. So, I'm not
> quite sure what you're referring to.
>
> - Jonathan M Davis

This might be how it works today, but I think it's a broken design. 
AssertError MUST be SAFELY catchable to be able to write unit testing 
frameworks.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list