[dmd-internals] Throwing Errors

Don Clugston dclugston at googlemail.com
Sat Mar 17 09:02:25 PDT 2012


On 17 March 2012 16:00, Jacob Carlborg <doob at me.com> wrote:
>
> On 15 mar 2012, at 23:57, Jonathan M Davis wrote:
>
>> On Thursday, March 15, 2012 15:25:32 Walter Bright wrote:
>>>
>>> If you want to recover, use an Exception.
>>
>> In general, I agree. It's just that there are a few cases where it makes
>> sense. The main one has to do with unit tests. In some cases, it makes sense
>> to catch an AssertError within a unit test, because assert is what's used in
>> unit tests. For instance, some programmers want to test their in contracts.
>> The biggest case though is that some programmers want to build more extensive
>> unit testing frameworks on top of the built-in one. And to do that, you have
>> to catch AssertErrors. Personally, I see no need for such frameworks, but some
>> people (e.g. Jacob Carlborg) definitely want them, and if AssertErrors skip
>> scope statements, finally blocks, or destructors, that's going to cause major
>> problems for their frameworks.
>
> I see three ways to solve this:
>
> * Make it safe to catch errors
> * Make assert throw an exception
> * Make the onAssertError callback usable
>
> Is it possible we can agree on something here or would I need to have my own "assert" function.

If something is derived from Throwable, it should be catchable.
The whole point of using the exception mechanism is so that the stack
should be unwound. If you are not going to unwind the stack, don't
make it an exception -- make it a fatal error.

As I said in a previous post, it is possible to add a bool to Error
which indicates if it is guaranteed to be safe, or without guarantee.
And I think that what's you'd hope for an systems programming
language.


More information about the dmd-internals mailing list