Possible bug with AppDomain.CurrentDomain.UnhandledException

A

Alex Glass

Im using the following code to test the unhandled exception feature and yet
on my development machine it works properly (i.e. it is able to consume the
exception) but on my test machine the event handler fails to trigger. Is
there something I am missing here? This code below comes from the help
files. I am using .NET v1.1, my development machine had installed .NET with
Visual Studio whereas I installed the framework on my test machine using the
redistributable exe file dotnetfx.exe

Output on Dev machine:
Catch clause caught : 1
MyHandler caught : 2
Press <ENTER>

Output on test machine:
Catch clause caught : 1

....Then window pops up
"Application has generated an exception that could not be handled.
Process id=0x1b0 .... Thread id=0x314 ....."

I would prefer if this window never appeared it looks very unprofessional
for my application.
Any help would be greatly appreciated.

----------------------------------------------------------------------------------------------------------------------
Module Module1

Sub Main()
Dim currentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler currentDomain.UnhandledException, AddressOf MyHandler

Try
Throw New Exception("1")
Catch e As Exception
Console.WriteLine("Catch clause caught : " + e.Message)
End Try

Throw New Exception("2")
End Sub 'Main


Sub MyHandler(ByVal sender As Object, ByVal args As
UnhandledExceptionEventArgs)
Dim e As Exception = DirectCast(args.ExceptionObject, Exception)
Console.WriteLine("MyHandler caught : " + e.Message)
Console.WriteLine("Press <ENTER>")
Console.ReadLine()
End Sub 'MyUnhandledExceptionEventHandler
End Module
 
A

Alex Glass

In addition i would like to clarify. The event triggers the
UnhandledException() function however it doesnt prevent the ugly window
("Application has generated an exception that could not be handled") from
being displayed to the end user. Is it possible to avoid this window from
being displayed?
 
T

Tom Krueger [MSFT]

Hey Alex,

Check out this blog post for how to handle unhandled exceptions.
http://weblogs.asp.net/tom_krueger/archive/2005/02/17/375602.aspx

It would seem to me that since you didn't start the application, the
AppDomain isn't setup properly. However, I really don't know much about how
the AppDomain works. If there is some reason you can't do it how my blog
post describes reply again with a more detailed question as to what your are
trying to do.

--
Tom Krueger

My Blog - http://weblogs.asp.net/tom_krueger
Smart Client DevCenter - http://msdn.microsoft.com/smartclient/
Mobile DevCenter - http://msdn.microsoft.com/mobility

This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top