On 14-01-2011 19:06, mp wrote:
> say i want to get an object from another objects method return
> List<string> keylist = xlrdr.RangeValueList();
>
> if keylist could be null...would i
> if(keylist != null)
> {
> foreach (string str in keylist)
> { Debug.Print(str); }
> }
> else
> {...handle null condition}
>
> or should one just try
>
> try
> { foreach (string str in keylist)
> { Debug.Print(str); }
> }
> catch
> {...handle exception}
>
>
> or should RangeValueList have raised an exception instead of returning null?
> so the calling code doesn't have to mess with it
> ?
You should not use try catch to handle null pointers, so with that
API then you should test for null.
My preferences would probably be either throw an exception or
returning a List with no elements depending on what makes sense
in the specific context.
Arne
|