Null references redux

Yigal Chripun yigal100 at gmail.com
Sun Sep 27 00:39:23 PDT 2009


On 27/09/2009 03:35, Walter Bright wrote:
> Yigal Chripun wrote:
>> An exception trace is *far* better than a segfault and that does not
>> require null values.
>
> Seg faults are exceptions, too. You can even catch them (on windows)!

No, segfaults are *NOT* exceptions. the setup you mention is windows 
only as Andrei said and for *nix is irrelevant. I develop on Unix 
(solaris) and segfault are a pain to deal with.

furthermore, even *IF* segfaults were transformed in D to exceptions 
that still doesn't make them proper exceptions because true exceptions 
are thrown at the place of the error which is not true for segfaults.


T foo() {
   T t;
   ...logic
   if (error) return null;
   return t;
}

now, foo is buried deep in a lib.

user code has:

T t = someLib.foo();
... logic

t.fubar = 4; //segfault t is null

how is it better to segfault in t.fubar as opposed to throw an exception 
inside foo?







More information about the Digitalmars-d mailing list