null dereference exception vs. segfault?
bearophile
bearophileHUGS at lycos.com
Mon Aug 2 10:33:14 PDT 2010
Mafi:
> If you want a NullPointerException as part of your program flow, you can
> use enforce() (in std.contracts I think). I don't think catching a
> NullPointerException in a big code block where you don't know which
> dereferencing should fail is good style.
enforce() is not a panacea (panchrest); as far as I know DMD doesn't inline any function that contains enforce(). So sometimes an assert() is better, especially if it's inside a contract (precondition, etc). DesignByConstrac-style programming is not something that just happens, you have to train yourself for some time for it.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list