|
Yes,but i english is bad,Please forgive me.
|
|
|
|
|
I really don't have any idea about what exactly defensive programming is
|
|
|
|
|
Wiki[^]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Let's say I build a function that takes an Object as parameter and the Object is Nothing/null... Don't you want/need to throw a ReferenceNullException? Not doing so and pretending everything went well seems like a code smell to me (and I've worked with code that does exactly that). If the programmer fails to Catch the Exception that's his problem, not mine. If the state of my Class/Library becomes inconsistent as a result of an Exception then that's my problem, but even more the programmer's who uses it
Maybe I'm misunderstanding the concept and I should take judo lessons...
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}
|
|
|
|
|
Totally agree - catch what you can handle otherwise bubble it up the call stack.
|
|
|
|
|
Right, but I don't think the question implied that.
I think that throwing a more descriptive Exception is what's needed there -- tell the caller which parameter was null.
|
|
|
|
|
The parameter that was supposed to tell the caller which parameter was null!
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}
|
|
|
|
|
Assuming the function's contract calls for a non-null parameter, I would throw an ArgumentNullException instead of the more general ReferenceNullException .
/ravi
|
|
|
|