Link to home
Start Free TrialLog in
Avatar of andyw27
andyw27

asked on

Error Handling

Hi,

I've setup a fairly simple error handling system on my website.  Basically I use GetLastError() to capture an exception, and then gets logged to a database.  The page then redirects.

This is the code I have added to the global.asax file

 void Application_Error(object sender, EventArgs e)
        {
            using (StoreDataContext Data = new StoreDataContext())
            {
                Exception ExceptionToLog = Server.GetLastError();
                Error NewError = new Error();
                NewError.ErrorMessage = ExceptionToLog.Message;
                NewError.ErrorStackTrace = ExceptionToLog.StackTrace;
                NewError.ErrorURL = Request.Url.ToString();
                NewError.ErrorDate = DateTime.Now;
                Data.Errors.InsertOnSubmit(NewError);
                Data.SubmitChanges();
            }
            Response.Redirect("~/error.aspx");
        }

Open in new window

     

This appears to working fine, but I'd to know if its possible to capture more information?  I have this information but I don't know how to pass it?

I did look at throwing a new exception, as this appears to give the ability to pass a string message as well as an exception, but this didn't seem to work.

Any suggestions?
Avatar of Jerry Miller
Jerry Miller
Flag of United States of America image

I will generally wrap blocks in the methods on my pages as well. This is where you can log a lot more details. I have an InsertLogEvent method that controls the database insert.

          Try
           ....your code here.........
        Catch ex As Exception
            commonFunctions.insertLogEvents(LOG_EVENT_ERROR, ex.ToString())
        End Try
ASKER CERTIFIED SOLUTION
Avatar of tipsybroom
tipsybroom
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial