Catching exceptions in other assemblies.

S

Simon Tamman

I have an object named DisasterRecovery. The Ctor of this object is this:

private DisasterRecovery()
{
Application.ThreadException+=
new
System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException
+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}

It's private as only 1 static instance of this object is created and
accessed via a singleton.
I would have thought that all exceptions that occur in my program would have
been caught by this object but this doesn't seem to be the case. Exceptions
that occur in different assemblies do not appear to be caught (the
stacktrace shows nothing of this object getting involved at any stage).
Is there a generic method of catching exceptions in other assemblies (like
Application.AssemblyException or something) or is my implementation of this
object incorrect?

Kind Regards

Simon
 
S

Simon Tamman

I do. It's the first one that is hooked up in the Ctor of the class I
posted.
I handle both Thread and Unhandled.
 
N

Nicholas Paldino [.NET/C# MVP]

Simon,

The logical boundary for exceptions being thrown is not an assembly.
Rather, it is the thread that is currently executing.

The code you have will do two things. The first is handle ^unhandled^
exceptions that are thrown in the UI thread (where the static Run method on
the Application class is called).

The second will handle exceptions that are thrown on all threads in the
application which are ^unhandled^.

If there is a try/catch block around the area where exceptions are
thrown, then these methods will not be called. These two methods only
handle unhandled exceptions.

If you find this is not the case, then provide a complete example
showing the behavior.

Hope this helps.
 
S

Simon Tamman

No, it's neither performing any remoting or handling the exceptions within
it's own little try catches.
It's going to be difficult to provide a complete solution as this is the
combination of several assemblies.
However if it's a suprise to everyone else then this v.probably means that
i'm ballsing this up somehow.
I'll work on trying to replicate this problem is a simple example and repost
it some point later.

Thanks for your help everyone.


Nicholas Paldino said:
Simon,

The logical boundary for exceptions being thrown is not an assembly.
Rather, it is the thread that is currently executing.

The code you have will do two things. The first is handle ^unhandled^
exceptions that are thrown in the UI thread (where the static Run method on
the Application class is called).

The second will handle exceptions that are thrown on all threads in the
application which are ^unhandled^.

If there is a try/catch block around the area where exceptions are
thrown, then these methods will not be called. These two methods only
handle unhandled exceptions.

If you find this is not the case, then provide a complete example
showing the behavior.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Simon Tamman said:
I have an object named DisasterRecovery. The Ctor of this object is this:

private DisasterRecovery()
{
Application.ThreadException+=
new
System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException
+=new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}

It's private as only 1 static instance of this object is created and
accessed via a singleton.
I would have thought that all exceptions that occur in my program would
have
been caught by this object but this doesn't seem to be the case.
Exceptions
that occur in different assemblies do not appear to be caught (the
stacktrace shows nothing of this object getting involved at any stage).
Is there a generic method of catching exceptions in other assemblies (like
Application.AssemblyException or something) or is my implementation of
this
object incorrect?

Kind Regards

Simon
 

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