On Fri, Jan 17, 2014 at 10:00:26AM -0800, H. S. Teoh wrote: [...] > If Andrei's proposal were extended so that .init can be overridden by a > member *function*, then this would work: > > class NullTracker { > override typeof(this) init(string _file=__FILE__, > size_t _line = __LINE__) > { > class Impl : NullTracker { > string file; > size_t line; > this(string f, size_t l) { file=f; line=l; } > > override void method1() { nullDeref(); } > override void method2() { nullDeref(); } > ... > void nullDeref() { > // N.B.: puts the *source* of the > // null in the Exception. > throw new Exception( > "Null dereference", > file, line); [...]
P.S. A better message might be "Null dereference, uninitialized object from %s:%d", to distinguish the site of the null dereference vs. its ultimate source. T -- "How are you doing?" "Doing what?"