c# - how to continue a foreach loop -


i have each loop below , know how able continue after exception has been thrown goes onto next next array index, , system doesn't fail.

try { //making name array , other checks      foreach (string s in namearry)     {         var timelinedata = oauthtwitterwrapper.getmytimeline(s);         twitterdata.timelinedata(timelinedata, s, int.parse(dr["clientid"].tostring()));         //  var followersid = oauthtwitterwrapper.getfolowersid(s);         // var loc = oauthtwitterwrapper.getfolowersloc(followersid);         //  twitterdata.follower(loc, s);     } } catch(exception ex) {     //logging exception  } 

ideally try avoid exceptions. in case can handle exception within foreach loop. in following examples have added necessary checks avoid exception occuring in first place. this

foreach (string s in namearry) {     try     {         var timelinedata = oauthtwitterwrapper.getmytimeline(s);         if(timelinedata!=null)         {              int clientid;              if(int.tryparse(dr["clientid"].tostring(), out clientid))              {                   twitterdata.timelinedata(timelinedata, s, clientid);                          }         }     }     catch(exception exp)     {         //do logging here.     } } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -