Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Throw new ApplicationException
Message
De
07/09/2006 11:47:12
 
 
À
07/09/2006 11:24:50
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01151872
Message ID:
01151891
Vues:
30
Hi Jerry,

I believe you're catching a different exception than you're Throwing. I.e. you're Throwing an ApplicationException, but you're Catching an ArgumentException.

Bill

>I am using VS .Net 2005 and I am trying to throw an ApplicationException() inside of my method and trap that error with a TRY/CATCH block. However, I can't get this to work. Below is my code.
>
>
>public void function1()
>{
>    try
>    {
>    	//This should trap error.
>        this.function2();
>    }
>    catch (ArgumentException ae)
>    {
>        MessageBox.Show("An error occurred! -> " + ae.Message);
>    }
>}
>
>public bool function2()
>{
>    string lc_value = "";
>    if (lc_value == "")
>    {
>        throw new ApplicationException("My Error occurred!");
>    }
>
>    //Continue normal operation.
>
>    return true;
>}
>
>
>I would expect that when the throw new ApplicationException() was triggered, that my CATCH block would gain control and display my custom error message. However, what actually happens is that a VS error dialog displays my custom message and my CATCH block is not called.
>
>How can I trigger a error and capture it with a TRY/CATCH block?
>
>Thanks,
>
>Jerry
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform