runtime hook for Crash on Error

Timon Gehr timon.gehr at gmx.ch
Wed Jun 6 14:35:14 PDT 2012


On 06/06/2012 11:04 PM, Lars T. Kyllingstad wrote:
> On Wednesday, 6 June 2012 at 19:27:31 UTC, Timon Gehr wrote:
>> On 06/06/2012 07:18 PM, Lars T. Kyllingstad wrote:
>>> Besides OutOfMemoryError, I can only think of two other Errors that
>>> would make this a hassle: AssertError and RangeError. However, both of
>>> these signify problems with the program logic, and unwinding the stack
>>> is probably a bad idea anyway, so why not simply make these abort()?
>>>
>>> -Lars
>>>
>>
>> In the current implementation, in contract checking may catch
>> AssertErrors and resume the program normally.
>
> I'm not sure I understand what you mean. Are you suggesting catching
> AssertErrors thrown by in contracts, thereby using contracts as a means
> of checking input? If so, I would say you are using contracts in the
> wrong way.
>
> -Lars
>

I was not describing an usage pattern. This is built-in behaviour.

int throwAssertError(){
     writeln("now throwing an AssertError");
     throw new AssertError("!");
}

class C{
     void foo()in{throwAssertError();}body{}
}
class D: C{
     override void foo()in{}body{}
}

void main(){
     C c = new D;
     c.foo(); // assert error thrown and caught
}


More information about the Digitalmars-d mailing list