c# - Try Catch inside Foreach Loop -


what's best way write following code:

foreach (datarow row in table.rows) {     try     {         sendemail(emailadress); //method send emails         messagesent(true);     }      catch (exception)     {         messagesent(false);         break;     } }  void messagesent(boolean issuccesful) {     if (issuccesful)     {         response.bufferoutput = true;         response.redirect("~/page.aspx");     }     else     {         lblsent.text = "email has failed.";     } } 

i'm trying iterate through datatable , send email different emails listed in datatable , redirect page.aspx on success after of emails in datatable have been sent. however, if emails fail, show label lblsent. don't know if best way it.

among other things, shouldn't catching exception type. catch exceptions know how handle. cannot handle nullreferenceexception or argumentnullexception, don't try. catch exceptions thrown while sending email. things smtpexception or formatexception (for email address format errors).


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -