Unhandled Exception and Control.EndInvoke

  • Thread starter Thread starter Michael E. Pouliot
  • Start date Start date
M

Michael E. Pouliot

The documentation for Control.BeginInvoke states "Exceptions within the
delegate method are considered untrapped and will be sent to the
application's untrapped exception handler". However, other articles
reference the fact that Control.EndInvoke will marshal an Exception back to
the caller. Upon attempting this, it appears that both are true. The
Exception is marshaled back, but an Unhandled Exception is also raised.
Furthermore, I cannot seem to catch the Unhandled Exception by implementing
handlers for either Application.ThreadException or
AppDomain.UnhandledException.

Optimally, I would want the runtime to not generate an Unhandled Exception,
since it appears to marshal the Exception just fine. Has anyone else dealt
with this issue?

Thanks,
MP
 
Michael E. Pouliot said:
The documentation for Control.BeginInvoke states "Exceptions within the
delegate method are considered untrapped and will be sent to the
application's untrapped exception handler". However, other articles
reference the fact that Control.EndInvoke will marshal an Exception back
to the caller. Upon attempting this, it appears that both are true. The
Exception is marshaled back, but an Unhandled Exception is also raised.
Furthermore, I cannot seem to catch the Unhandled Exception by
implementing handlers for either Application.ThreadException or
AppDomain.UnhandledException.

Optimally, I would want the runtime to not generate an Unhandled
Exception, since it appears to marshal the Exception just fine. Has
anyone else dealt with this issue?

Thanks,
MP
FYI - I determined why I wasn't able to catch the Unhandled Exception. It
turns out (probably obviously) that Application.ThreadException is specific
to the thread on which the exception is thrown. In my situation, I had
created a secondary thread which was running its own message pump (via
Application.Run()). Once I setup the event handler in that thread, I was
able to catch the Unhandled Exception. The runtime still both marshals the
exception and raises an Unhandled Exception, but at least now I can suppress
the Unhandled Exception dialog box.

MP
 
Back
Top