4

I have the following error in my output.aspx page sometimes:

Exception Details: System.Web.HttpException: Request timed out.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): Request timed out.]

Is it a good idea to catch this exception? Where do I do that as my output.aspx.cs has a Page_Load and that function calls RunTable(). Should I put a try catch block around that functions content?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
cdub
  • 24,555
  • 57
  • 174
  • 303
  • 1
    Catching an exception is almost always a rather _bad idea_. Better solve the root/cause of the exception, not the symptoms (i.e. the exception). – Uwe Keim Aug 30 '12 at 19:08

1 Answers1

6

catch exception at application level

    void Application_Error(object sender, EventArgs e)
{
  // Code that runs when an unhandled error occurs

  // Get the exception object.
  Exception exc = Server.GetLastError();

  // Handle HTTP errors
  if (exc.GetType() == typeof(HttpException))
  {
    // The Complete Error Handling Example generates
    // some errors using URLs with "NoCatch" in them;
    // ignore these here to simulate what would happen
    // if a global.asax handler were not implemented.
      if (exc.Message.Contains("NoCatch") || exc.Message.Contains("maxUrlLength"))
      return;

    //Redirect HTTP errors to HttpError page
    Server.Transfer("HttpErrorPage.aspx");
  }

  // For other kinds of errors give the user some information
  // but stay on the default page
  Response.Write("<h2>Global Page Error</h2>\n");
  Response.Write(
      "<p>" + exc.Message + "</p>\n");
  Response.Write("Return to the <a href='Default.aspx'>" +
      "Default Page</a>\n");

  // Log the exception and notify system operators
  ExceptionUtility.LogException(exc, "DefaultPage");
  ExceptionUtility.NotifySystemOps(exc);

  // Clear the error from the server
  Server.ClearError();
}
user229044
  • 232,980
  • 40
  • 330
  • 338
Hassan Boutougha
  • 3,871
  • 1
  • 17
  • 17
  • where do i put this code? in my output.aspx or output.aspx.cs or somewhere else? – cdub Aug 30 '12 at 19:07
  • in global.asax file http://msdn.microsoft.com/en-us/library/24395wz3(v=vs.100).aspx – Hassan Boutougha Aug 30 '12 at 19:08
  • if it's in my global.asax file, will the response.write code in your answer be put back into my output file as output? – cdub Aug 30 '12 at 19:10
  • 2
    While it is good to have a central error handler as a _last ressort_, I do believe he should better find and fix the _cause_ of the exception. – Uwe Keim Aug 30 '12 at 19:10
  • @UweKeim I am agree, first have a central error handler to be sure to catch errors secondly manage exception at low level as possible – Hassan Boutougha Aug 30 '12 at 19:11
  • i would find the cause but it's pretty complex. The app sends a stored procedure to the sql server which runs a bunch of sql assemblies in a single thread and does a bunch of statistical computations, thus running some very crazy math problems on multiple browsers casued sql server to slow, thus the web app times out sometimes. – cdub Aug 30 '12 at 19:13