Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Try/Catch Routine Not Working
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00985235
Message ID:
00985295
Vues:
35
This message has been marked as a message which has helped to the initial question of the thread.
Todd,

>Oops. My mistake. The error was actually being thrown outside the try/catch routine because I was trying to change the connection string while the connection was still open (1st line of code below).

I am glad to hear you figured it out.

>BTW: In this thread you mentioned "Throwing the error back on the stack". Would this cause the error to be caught by the next applicable Catch routine?

You can nest try..catch, so if you rethrow the exception from the catch the exception will be caught by the try...catch enclosing the inner try...catch. (I hope that makes sense)
try
{
  //do something #1
  try
  {
    // do something #2
  }
  catch (Exception Ex)
  {
    // i don't feel like doing anything with this
    throw new Exception("rethrow",Ex);
  }
  //do something #3
}
catch (Exception Ex)
{
  // here you will catch an exception from #1 or #3 or the rethrown exception
}
Hope this code sample explains you question.



What I do is I always have a try catch in Main()
static void Main() 
{
	try
	{
		Application.Run(new frmMain());
	}
	catch(Exception Ex)
	{
		MessageBox.Show(Ex.ToString(),"Exception caught");
	}
}
this way I can always control what the user will see if an error sneaks by me and makes it all the way to Main().

Einar
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform