runtime hook for Crash on Error

Lars T. Kyllingstad public at kyllingen.net
Wed Jun 6 14:50:18 PDT 2012


On Wednesday, 6 June 2012 at 21:35:15 UTC, Timon Gehr wrote:
> 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
> }

Ah, now I see what you mean.  I didn't know that.

-Lars


More information about the Digitalmars-d mailing list