[dmd-internals] Throwing Errors

Steve Schveighoffer schveiguy at yahoo.com
Thu Mar 22 13:07:09 PDT 2012


What about calling onAssertError *after* the assert error is caught in the runtime (outside main)?  That gives you a way to handle unit test failures by e.g. logging them somewhere.  At least it's better than nothing.


-Steve




>________________________________
> From: Sean Kelly <sean at invisibleduck.org>
>To: Discuss the internals of DMD <dmd-internals at puremagic.com> 
>Sent: Monday, March 12, 2012 5:29 PM
>Subject: Re: [dmd-internals] Throwing Errors
> 
>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.
>_______________________________________________
>dmd-internals mailing list
>dmd-internals at puremagic.com
>http://lists.puremagic.com/mailman/listinfo/dmd-internals
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-internals/attachments/20120322/dc2155df/attachment.html>


More information about the dmd-internals mailing list