|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Global Error HandlerHi Guys
I have two questions. 1. Is there a way to set a handler to .NET application so that in case of not caught exception my handler is called before application shutdown. I want to send an email from this handler with details of error. 2. Is there a way to capture the text (with stack frame etc) displayed in a dialog which is shown when unhandled execption is thrown Thanks in advance for your help Regards Yeghia All your uncaught errors go though the Global.asax file
void Application_Error(object sender, EventArgs e) { errors ApplicationError = new errors(); ApplicationError.LogApplicationError(Error.GetType().ToString(),Request.Path.ToString(), Request.Url.ToString(), Error.Source.ToString(), Error.Message.ToString(), Error.StackTrace.ToString(), Error.TargetSite.ToString()); Server.ClearError(); ApplicationError.Dispose(); Server.Transfer("error.aspx?Message=" + Error.GetType().ToString(), false); } Here you can process that error how you see fit. We try to write our unhandled errors to an SQL log table. If this fails, we contact to SMTP and see the error report directly to the programmer. The parameter list above is the more common items you can return. -- Show quoteJP ..NET Software Developer "yeghia (sosy)" wrote: > Hi Guys > > I have two questions. > 1. Is there a way to set a handler to .NET application so that in case of > not caught exception my handler is called before application shutdown. I > want to send an email from this handler with details of error. > 2. Is there a way to capture the text (with stack frame etc) displayed in a > dialog which is shown when unhandled execption is thrown > > Thanks in advance for your help > > Regards > Yeghia > > > That's *if* you are talking about an ASP.NET web applicationa. The OP
didn't specify. Show quote "JP" <J*@discussions.microsoft.com> wrote in message news:DF2B09D8-CCBB-458C-B843-542F3DE34277@microsoft.com... > All your uncaught errors go though the Global.asax file > > void Application_Error(object sender, EventArgs e) > { > errors ApplicationError = new errors(); > ApplicationError.LogApplicationError(Error.GetType().ToString(),Request.Path.ToString(), > Request.Url.ToString(), Error.Source.ToString(), Error.Message.ToString(), > Error.StackTrace.ToString(), Error.TargetSite.ToString()); > Server.ClearError(); > ApplicationError.Dispose(); > Server.Transfer("error.aspx?Message=" + Error.GetType().ToString(), > false); > > } > > Here you can process that error how you see fit. We try to write our > unhandled errors to an SQL log table. If this fails, we contact to SMTP > and > see the error report directly to the programmer. The parameter list above > is > the more common items you can return. > > -- > JP > .NET Software Developer > > > "yeghia (sosy)" wrote: > >> Hi Guys >> >> I have two questions. >> 1. Is there a way to set a handler to .NET application so that in case of >> not caught exception my handler is called before application shutdown. I >> want to send an email from this handler with details of error. >> 2. Is there a way to capture the text (with stack frame etc) displayed in >> a >> dialog which is shown when unhandled execption is thrown >> >> Thanks in advance for your help >> >> Regards >> Yeghia >> >> >> Yes it is possible, look over here for some examples on how to have an
handler catch all the unhandled exceptions : http://www.codeproject.com/dotnet/unhandledexceptions.asp http://www.codeproject.com/dotnet/ExceptionHandling.asp http://www.codeproject.com/dotnet/SafeForm.asp However be careful of a few things : -behaviour might differ if you run your program with or without the debugger -behaviour might differ if you have visual studio installed or not on the computer -Make sure that it works with different forms (some people seems to have problems : unhandled exceptions of one form are catch and exceptions from another form are not) yeghia (sosy) schreef: Show quote > Hi Guys > > I have two questions. > 1. Is there a way to set a handler to .NET application so that in case of > not caught exception my handler is called before application shutdown. I > want to send an email from this handler with details of error. > 2. Is there a way to capture the text (with stack frame etc) displayed in a > dialog which is shown when unhandled execption is thrown > > Thanks in advance for your help > > Regards > Yeghia |
|||||||||||||||||||||||