PC Review


Reply
Thread Tools Rate Thread

check with If or just use try

 
 
mp
Guest
Posts: n/a
 
      15th Jan 2011
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
?
thanks
mark


 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      15th Jan 2011
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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spell check -- text marked skip spelling and grammar check =?Utf-8?B?RGF2aWQgQS4=?= Microsoft Word Document Management 8 9th Aug 2008 11:47 PM
Asp.net Treeview Clientscript - Auto Check Child Notes After Check Parent Node Sylvie Microsoft C# .NET 1 9th Oct 2007 02:25 PM
Treeview Clientscript - Auto Check Child Notes After Check Parent Node Sylvie Microsoft ASP .NET 1 9th Oct 2007 02:25 PM
In outlook get message "Spell check cannot check items...try agai =?Utf-8?B?am1yYW5jaG1hbg==?= Microsoft Outlook Discussion 1 28th Sep 2006 10:26 PM
Xp:Check Disk:Tools:Check Now:Both Options:reboot countdown does not complete? RAS Windows XP General 3 1st Feb 2005 06:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:30 AM.