Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Throw new ApplicationException
Message
De
07/09/2006 11:24:50
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Throw new ApplicationException
Divers
Thread ID:
01151872
Message ID:
01151872
Vues:
250
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform