AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

[How] to Display Exception Message in Asp.Net

By pushpam abhishek
Listen to this article

How to Display Exception Message in Asp.Net

How to Display Exception Message in Asp.Net

Description

In these articles, we learn How to Display Exception Message in Asp.Net, Exception Message is nothing but an error message it can raise when run program output through code behind then it will come if we have any kind of error in our code. Here we will Check Exception Message, Stack trace, Source of that Message, Target Site with alert box through code behind.

Step 1: Drag and Drop Button Control in Webpage.

Step 2: Generate the Click event and create a try-catch block so we can easily get an exception while error raised.
protected void RaiseException(object sender, EventArgs e)
{
  try
  {
    int i = int.Parse("Umesh");
  }
  catch (Exception ex)
  {
    string message = string.Format("Message: {0}\\n\\n", ex.Message);
    message += string.Format("StackTrace: {0}\\n\\n", ex.StackTrace.Replace(Environment.NewLine, string.Empty));
    message += string.Format("Source: {0}\\n\\n", ex.Source.Replace(Environment.NewLine, string.Empty));
    message += string.Format("TargetSite: {0}", ex.TargetSite.ToString().Replace(Environment.NewLine, string.Empty));
    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + message + "\");", true);
  }
}
Step 3: Now run in the browser and click on the button to generate an exception message in the alert box.

Share this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments