Home All Groups Group Topic Archive Search About

Global Error Handler

Author
10 Oct 2006 8:55 PM
yeghia (sosy)
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

Author
10 Oct 2006 9:13 PM
JP
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


Show quote
"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
>
>
>
Author
10 Oct 2006 9:54 PM
Scott M.
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
>>
>>
>>
Author
11 Oct 2006 12:06 PM
burettethomas
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

AddThis Social Bookmark Button