Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Throw new ApplicationException
Message
From
07/09/2006 11:24:50
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Throw new ApplicationException
Miscellaneous
Thread ID:
01151872
Message ID:
01151872
Views:
247
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
Next
Reply
Map
View

Click here to load this message in the networking platform