[dmd-internals] Throwing Errors

Sean Kelly sean at invisibleduck.org
Mon Mar 12 14:29:41 PDT 2012


On Mar 12, 2012, at 1:13 PM, Jacob Carlborg wrote:

> On 12 mar 2012, at 21:06, Alex wrote:
> 
>> It would be hard to write a framework around D unit tests, for
>> instance, where you need to catch AssertErrors if things weren't
>> cleaned up properly (or if it just called abort()). That's just the
>> first thing that comes to mind.
> 
> I completely agree. That's what I've been discussion in the "learn" newsgroup. I had a look through the source code of druntime and found "onAssertError". I don't know if it's used or not but sounds exactly like the function I need. But unfortunately the function to set the assert handler is deprecated. 
> 
> http://dlang.org/phobos/core_exception.html#onAssertError
> http://dlang.org/phobos/core_exception.html#setAssertHandler

The handler is deprecated because DMD doesn't generate a valid call stack for _d_assert (which calls onAssertError) so it's impossible to return from the assert handler without throwing.  This rendered the assert handler largely useless and after a few years of no one using it I decided to deprecate it.  I'd be happy to keep the assert handler if people actually want it though, or if DMD changes its codegen.  Personally, I'd like to be able to assert without throwing in some testing situations, and overriding a handler seems like an appropriate way to do this.


More information about the dmd-internals mailing list