Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Exception Handling ASP.Net  - Continue with Code

Posted on 2007-11-21
6
Medium Priority
?
1,187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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