Suggestion: "fix" assert(obj)

Lionello Lunesu lio at lunesu.remove.com
Fri Jun 15 05:36:48 PDT 2007


Walter Bright wrote:
> Kristian Kilpi wrote:
>> The problem is that
>>
>>   assert(obj);
>>
>> does not first check if 'obj' is null.
> 
> Yes it does, it's just that the hardware does the check, and gives you a 
>  seg fault exception if it is null.

You're right, but the problem is that you need a debugger attached to 
catch that exception, whereas asserts help you with debugging without 
any debugger. This is part of the strength of assert. Many problems will 
cause some kind of exception that's theoretically catchable in a 
debugger, but we write asserts nonetheless, right?

L.



More information about the Digitalmars-d mailing list