Solved

Exception Handling ASP.Net  - Continue with Code

Posted on 2007-11-21
6
1,138 Views
Last Modified: 2013-11-26
I need help with how to continue with my code even after I face an exception.
The NotifyUser() method gets all the accounts for which email has to be sent. For each of the account it calls the Send Mail() method, passing the parameters. In the SendMail method.If one of the emails cannot be sent then it should keep a log of that record and then continue with sending the rest of the emails ..it should go back to the next record in the NotifyUser method.

I need help with how to continue with my code even after I face an exception.

The NotifyUser() method calls the Send Mail() method.

private void NotifyUsers(parameters){

try

 {

  Gets a data set of accounts for which emails have to be sent.

  for(each of the accounts )

 {

Recovers the fields from the dataset and puts them in local variables like say account number, email   address, email   message, maturity date.

Calls the method Send Mail(with parameters mentioned above )

}

 }

catch

 {

  }

}

private void SendMail(parameters){

try

 {

 Calls stored procedure uspInsertmail to send  email .

 }

Catch(e  Exception)

 {

   If any exception occurs 

   do some processing -  keep an account of the record in a separate table

  And then I need to go back to the next account in NotifyUser()  and try to send an  email. How do I go   back to the next record in NotifyUser() and continue with the code? This is my question.
 

  }

}

Open in new window

0
Comment
Question by:saswati_m
6 Comments
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20329304
MsgBox("Exception: " + Err.Description)

put it in the catch
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20329319
Remove try catch from the Notify stuff. like this.
private void NotifyUsers(parameters){
 

  Gets a data set of accounts for which emails have to be sent.

  for(each of the accounts )

 {

Recovers the fields from the dataset and puts them in local variables like say account number, email   address, email   message, maturity date.

Calls the method Send Mail(with parameters mentioned above )

 }

}
 

private void SendMail(parameters){

try

 {

 Calls stored procedure uspInsertmail to send  email .

 }

Catch(e  Exception)

 {

   If any exception occurs 

   do some processing -  keep an account of the record in a separate table

  And then I need to go back to the next account in NotifyUser()  and try to send an  email. How do I go   back to the next record in NotifyUser() and continue with the code? This is my question.

 

  }

}

Open in new window

0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 250 total points
ID: 20329323
When you actually call your sendmail, wrap it in another try/catch...
private void NotifyUsers(parameters){

try

 {

  Gets a data set of accounts for which emails have to be sent.

  for(each of the accounts )

 {

Recovers the fields from the dataset and puts them in local variables like say account number, email   address, email   message, maturity date.
 

//try sending the mail:

    try { 

        SendMail(); 

    } 

    catch (Exception ex) { 

    //Ignore exception

    } 
 
 

}

 }

catch

 {

  }

}

Open in new window

0
 

Author Comment

by:saswati_m
ID: 20330699
I already haev a try catch block in Send Mail
What code do i need to write in the catch block of SendMail so that it ignores the exception and continues execution..otherwise if I do not write anything then it will stop execution and the application terminates.
0
 

Author Closing Comment

by:saswati_m
ID: 31410414
yes you are right .. i should have another try catch block
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now