PC Review


Reply
Thread Tools Rate Thread

Catching exceptions in other assemblies.

 
 
Simon Tamman
Guest
Posts: n/a
 
      27th Aug 2006
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



 
Reply With Quote
 
 
 
 
Tasos Vogiatzoglou
Guest
Posts: n/a
 
      27th Aug 2006
Simon,

why don't you use Application.ThreadException ?

Regards,
Tasos

Simon Tamman wrote:
> 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


 
Reply With Quote
 
Simon Tamman
Guest
Posts: n/a
 
      27th Aug 2006
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.

"Tasos Vogiatzoglou" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Simon,
>
> why don't you use Application.ThreadException ?
>
> Regards,
> Tasos
>
> Simon Tamman wrote:
> > 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

>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      27th Aug 2006
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 Removed)

"Simon Tamman" <(E-Mail Removed)>
wrote in message news:bbjIg.16850$(E-Mail Removed)...
>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
>
>
>



 
Reply With Quote
 
Tasos Vogiatzoglou
Guest
Posts: n/a
 
      27th Aug 2006
So, do the other exceptions occur in an other appDomain ?

Simon Tamman wrote:
> 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.
>
> "Tasos Vogiatzoglou" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Simon,
> >
> > why don't you use Application.ThreadException ?
> >
> > Regards,
> > Tasos
> >
> > Simon Tamman wrote:
> > > 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

> >


 
Reply With Quote
 
Simon Tamman
Guest
Posts: n/a
 
      27th Aug 2006
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 [.NET/C# MVP]" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> 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 Removed)
>
> "Simon Tamman" <(E-Mail Removed)>
> wrote in message news:bbjIg.16850$(E-Mail Removed)...
> >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
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Catching exceptions Andy B. Microsoft C# .NET 3 16th Mar 2010 10:33 AM
Catching Exceptions Jeffrey Walton Microsoft C# .NET 5 25th Nov 2007 12:05 AM
catching exceptions bitshift Microsoft Dot NET Framework 4 31st Aug 2007 10:51 AM
catching all unhandled exceptions NickP Microsoft VB .NET 1 14th Feb 2006 11:49 PM
Catching ALL Unhandled Exceptions James Hancock Microsoft Dot NET Framework 5 13th Jan 2004 04:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:04 PM.