|
me too. these days we use the exception handling application block, so i return null after the ExceptionPolicy.HandleException code. that way, if the exception is not rethrown, the method returns null.
|
|
|
|
|
I do 2 & 3, I almost never throw an exception, habit I guess, I certainly test and deal with the empty collection I just consider an exception a worst case scenario.
I have a favourite rant about programming by error, you know try writing to the database and if it throws an exception then there is something wrong, drop wing squawk loudly and run in circles
|
|
|
|
|
If I'm returning a Value type, then I can't return 'null'. If the method is for generics, than I'll use the 'default' keyword, but again, for Reference types, that will still translate to 'null'. At work in a lot a places in the code there is a result code and an out parameter. When returning a list of items, if there are no items then I may return an empty list instead of 'null'. So basically, it depends on the situation and what is being returned.
Should I be more consistent?
|
|
|
|
|
No. You shouldn't. This is the same way (or style?) I do it here.
|
|
|
|
|
I use some agreed upon impossible value if value type is in question, null if reference type and empty collection for collections.
Exception get thrown only if it is really an error, condition that is not checked by program or it comes from the database.
It is consistent regardless of treating different objects differently.
|
|
|
|
|
Much The Same - It depends upon what makes sense to return rather than entrapping myself with some dogmatic formula to which one must adhere.
For example, it is often much more sensible (fool-proof?) to return an empty String in a method that returns a String object, rather than a null - the results of which are therefore always printable. This avoids a later test of the return when something, even if blank, will always be required.
Will this confuse other potential users - isn't that what documentation is for ? ?
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"As far as we know, our computer has never had an undetected error." - Weisert
"It's a sad state of affairs, indeed, when you start reading my tag lines for some sort of enlightenment. Sadder still, if that's where you need to find it." - Balboos HaGadol
|
|
|
|