Catching a RT Unhandled Exception Error

  • Thread starter Thread starter Steve Podradchik
  • Start date Start date
S

Steve Podradchik

Hi,

For our app, we'd like to have basically the same functionality as what .Net
automatically provides if an unhandled error somehow occurs in the app.
That is, the user sees some sort of warning and then, generally, the app
continues merrily along as if nothing had happened. This is typically what
we get with our app today, rather automatically. The only thing we'd like
to do is:

1. Replace the "An unhandled exception has occurred..." msg. with something
we write and
2. Have our app automatically capture the error message and stack trace and
send it to us (yes, after asking the user if that's OK).

How do we do that? We tried using a Try/Catch block around everything in
Main() and tried adding an event handler to AppDomain.UnhandledException.
When using a simple Try/Catch, the app ended after an error -- not what we
wanted. When adding a handler via AppDomain.UnhandledException, the event
simply seemed to never fire with Release code. In Debug code, the event
fired -- *after* the default .Net "An unhandled exception..." message!

So .. is there a simple way to basically trap an unexpected errors, send
them back to us, then continue the app if possible?

Thanks, Steve
 
Hello Steve,

Thanks for your post. I suggest you to handle unhandled exception via
AppDomain.UnhandledException. The reason why you cannot catch it in Release
code is that it may be cought by the JIT debugger before reaching your
handler. To work around the problem, you need to change the following
registry key to disable JIT debugging:

Set

HKEY_LOCAL_MACHINE\Software\Microsoft\.NetFramework\DbgJITDebugLaunchSetting
to the value 1

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Well, thanks for the reply but we all know that's not a very good solution.
First, an individual app shouldn't modify Net Framework global settings. In
fact, depending on the user's security settings, this might not be possible.
Moreover, it looks like a bug in the Net Framework if the JIT catches the
error before the framework raises the even for processing. Clearly I should
get the event first then decide whether to handle it or bubble it up. Is
this something that we should expect fixed in a forthcoming .Net release?

Thanks, Steve
 
Hi Steve,

Thanks a lot for your feedback. I will report it to our Developer Team, and
I believe they will take it into serious consideration.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top