473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Try Catch question

rrocket
116 100+
I am sending info to another site that goes down every now and then... In the event that it is down or another error occurs I would like to run a specific function so that the customer does not see that there is an issue, but I still get there information.

Here is what I have so far:
Expand|Select|Wrap|Line Numbers
  1. protected void btnSubmit_Click(object sender, EventArgs e)
  2.     {
  3.         //sendSmallShippingEmail();
  4.         try
  5.         {
  6.             SendtoX();
  7.         }
  8.         catch
  9.         {
  10.             sendSmallShippingEmail();
  11.         }
  12.     }
  13.  
Basically what I want to happen is to use just one or the other, not both. If the SendtoX does not work the function in the catch should work. Right now it is doing both if the site is working and just the email when the site is down. Any ideas? I have done some reading about try/catch, but there are no examples of using it the way I would like to. If there is a better way to deal with this please let me know.
Mar 13 '08 #1
5 902
r035198x
13,262 8TB
I am sending info to another site that goes down every now and then... In the event that it is down or another error occurs I would like to run a specific function so that the customer does not see that there is an issue, but I still get there information.

Here is what I have so far:
Expand|Select|Wrap|Line Numbers
  1. protected void btnSubmit_Click(object sender, EventArgs e)
  2.     {
  3.         //sendSmallShippingEmail();
  4.         try
  5.         {
  6.             SendtoX();
  7.         }
  8.         catch
  9.         {
  10.             sendSmallShippingEmail();
  11.         }
  12.     }
  13.  
Basically what I want to happen is to use just one or the other, not both. If the SendtoX does not work the function in the catch should work. Right now it is doing both if the site is working and just the email when the site is down. Any ideas? I have done some reading about try/catch, but there are no examples of using it the way I would like to. If there is a better way to deal with this please let me know.
Let the SendtoX() method return a variable maybe an int. Use that int to decide whether to call the sendSmallShippingEmail() method or not.
Mar 13 '08 #2
Plater
7,872 Expert 4TB
In the example you gave (Well If you make sure you say catch(Exception ee) ), the code in the Exception block should onnly be run if an exception is thrown.
I am thinking that somewhere in your SendtoX() function an exception is being thrown, but not until after it has done its job.
I would debug and see what exception is being thrown.
Mar 13 '08 #3
rrocket
116 100+
In the example you gave (Well If you make sure you say catch(Exception ee) ), the code in the Exception block should onnly be run if an exception is thrown.
I am thinking that somewhere in your SendtoX() function an exception is being thrown, but not until after it has done its job.
I would debug and see what exception is being thrown.
Yeah you were right... I printed the exception to a querystring and it says "Thread was being aborted". What is that supposed to mean?
Mar 13 '08 #4
rrocket
116 100+
Okay, I figured out what the issue was... I have a redirect at the end of the initial try function that was causing the thread aborting thing. When I put false at the end
Expand|Select|Wrap|Line Numbers
  1. Response.Redirect("/dev/thankyouemails/thankyouemail_sps.aspx?ReturnVal=" + ReturnedVal, false);
  2.  
  3. instead of
  4.  
  5. Response.Redirect("/dev/thankyouemails/thankyouemail_sps.aspx?ReturnVal=" + ReturnedVal);
  6.  
  7.  
it worked fine. From what I was reading it tells the page to quit processing the current page before moving on to the one it is redirecting. If I do not have that right please let me know. :)
Mar 13 '08 #5
Frinavale
9,735 Expert Mod 8TB
Okay, I figured out what the issue was... I have a redirect at the end of the initial try function that was causing the thread aborting thing. When I put false at the end
Expand|Select|Wrap|Line Numbers
  1. Response.Redirect("/dev/thankyouemails/thankyouemail_sps.aspx?ReturnVal=" + ReturnedVal, false);
  2.  
  3. instead of
  4.  
  5. Response.Redirect("/dev/thankyouemails/thankyouemail_sps.aspx?ReturnVal=" + ReturnedVal);
  6.  
  7.  
it worked fine. From what I was reading it tells the page to quit processing the current page before moving on to the one it is redirecting. If I do not have that right please let me know. :)

You are correct...the Response.Redirect method takes 2 parameters:
  • url: A String for specifying the target location.
  • endResponse: A Boolean that indicates whether execution of the current page should terminate.
Mar 17 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jacek Dziedzic | last post by:
Hi! In my main() function I have a last-resort exception construct that looks like this: int main() { try { // ... program code }
13
by: Woody Splawn | last post by:
I have a try catch statement in a fucntion that is supposed to return a true or a false My code looks like this: Try mySqlConnection.Open() Dim Da1 As New SqlDataAdapter("Select JnlType,...
7
by: Tiraman | last post by:
Hi , I am using allot the try catch in my code and the question is if it is good ? it will decrease my performance ? one more question
9
by: Michael MacDonald | last post by:
Does someone have a good site I can visit or explain the use of Try" and Catch foe exception/error handling. What is the logic behind this command and maybe an example would be great!!!! Mike_Mac...
2
by: Keith Kowalski | last post by:
I anm opening up a text file reading the lines of the file that refer to a tif image in that file, If the tif image does not exist I need it to send an email stating that the file doesn't exist...
5
by: Patrick Dickey | last post by:
Hello, All! I'm modifying some source code that I downloaded from Planet-source-code a while back, and have a question about Try Catch statements. Basically, I'm wondering if I can do a Try with...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
23
by: pigeonrandle | last post by:
Hi, Does this bit of code represent complete overkill?! try { //create a treenode TreeNode tn = new TreeNode(); //add it to a treeview tv.Nodes.Add(tn);
6
by: rhaazy | last post by:
I am looking for some feedback on using try catch statements. Usually when I start a project I use them for everything, but stop using them as often after the "meat n' potatos" of the project is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.