I have an ASP.NET web application, and I wanted to know how I could display an error message box when an exception is thrown.
For example,
try
{
do something
}
catch
{
messagebox.write("error");
//[This isn't the correct syntax, just what I want to achieve]
}
[The message box shows the error]
Thank you
You can handle default errors at the application level either by modifying your application's configuration or by adding an Application_Error handler in the Global. asax file of your application. You can handle default errors and HTTP errors by adding a customErrors section to the Web. config file.
Application level error handling allow to detect or handle web application level error handling so that its helps to handle and solve the particular error. Application level error handling can be done in 2 ways: 1. Add an Application_Error event handler to the global asax file for your web application.
using MessageBox.Show() would cause a message box to show in the server and stop the thread from processing further request unless the box is closed.
What you can do is,
this.Page.ClientScript.RegisterStartupScript(this.GetType(),"ex","alert('" + ex.Message + "');", true);
this would show the exception in client side, provided the exception is not bubbled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With