9

I am using the Application_Error event for handling the exceptions and it catches almost all exceptions correctly. However in some pages it catches with exception "File does not exist" and I am not able to find from where it exactly occurs. When I comment the Application_Error code, surprisingly that web page works fine.

My main concern is how can trace back to the line of code from where it threw to Application_Error function.

LosManos
  • 7,195
  • 6
  • 56
  • 107
Anto Varghese
  • 3,131
  • 6
  • 31
  • 38

4 Answers4

15

Use HttpContext.Current.Request.Url.ToString() to look at the file path of the missing file.

Bob Kaufman
  • 12,864
  • 16
  • 78
  • 107
Abhi
  • 151
  • 1
  • 3
0

To see the problem, on Application_Error event of Global.asax put:

public void Application_Error(object sender, EventArgs e) {
        // Code that runs when an unhandled error occurs
        Exception ex = Server.GetLastError();
        Console.WriteLine("Application_Error() -> " + ex.Message + "\n\nURL: " + HttpContext.Current.Request.Url, ex);

        if (ex is HttpUnhandledException)
            Context.ClearError(); // System.NullReferenceException
    }
0

hoooo....... just now solved my issue. During my debugging I had put one checkpoint in Appilcation_Error code and when execution reached it I could see the path of an image (path was wrong) which was loading at that time and which causes the exception. :)

Anto Varghese
  • 3,131
  • 6
  • 31
  • 38
0

Right in my case also in Jquery at lots of place used backgroung image uri & that did not exist, thats why this type of error.

Arun Rana
  • 8,426
  • 14
  • 67
  • 107