473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Logging (exceptions etc)

Hi,

I'm getting into the Trace-functionality in .NET, using it to provide some
much-needed logging across dlls in the project we're working on. However,
being a newbie, I'm wondering if some more experienced loggers can provide
me with some ideas as to how to log in a simple yet flexible manner. For
instance, I'd like the code to be as uncluttered as possible by Trace
statements.

As an example of basic logging functionality, I've come up with some
alternatives for logging exceptions that occur in an object:

1) Wrap the throwing of an exception in a method, which can handle any
logging before throwing the actual exception.

2) Handle logging in the constructors of my own hierarchy of exceptions.
This makes the logging more transparent in the code, but doesn't work for
standard .NET exceptions such as ArgumentNullException (I'd have to subtype
it).

3) Use a decorator object to wrap the original object, catch all exceptions,
write to log, and rethrow.

Any and all thoughts/comments are much appreciated!

Regards,
Einar

--
"If it was so, it might be; and if it were so, it would be; but as it isn't,
it ain't. That's logic" -- Lewis Carroll
Nov 16 '05 #1
16 2131
Hi,

Have you looked at the Exception Mangement Application Block at MSDN ?

The Exception Management Application Block provides a simple yet extensible framework for handling exceptions. With a single line of application code you can easily log exception information to the Event Log or extend it by creating your own components that log exception details to other data sources or notify operators, without affecting your application code. The Exception Management Application Block can easily be used as a building block in your own .NET application.

[ http://msdn.microsoft.com/library/de...ml/emab-rm.asp ]
Regards,
Saurabh Nandu

Nov 16 '05 #2
Hi,

Thanks for the tip. I actually did take a look at it a while ago, but at
that time I wasn't really into exception management the way I am now. I'll
take a fresh look at it, thanks.

Regards,
Einar

"Saurabh Nandu" <Sa**********@discussions.microsoft.com> wrote in message
news:F8**********************************@microsof t.com...
Hi,

Have you looked at the Exception Mangement Application Block at MSDN ?

The Exception Management Application Block provides a simple yet extensible framework for handling exceptions. With a single line of
application code you can easily log exception information to the Event Log
or extend it by creating your own components that log exception details to
other data sources or notify operators, without affecting your application
code. The Exception Management Application Block can easily be used as a
building block in your own .NET application.
[ http://msdn.microsoft.com/library/de...ml/emab-rm.asp ]

Regards,
Saurabh Nandu

Nov 16 '05 #3
As someone else wrote, start with the MS Exception Management block. You may
need to modify/extend it but it's a pretty good starting point.

I use a strategy that boils down to this...

If it's an exception that my own code throws then if it's the 1st time that
an exception has been thrown I log it. If it's being propagated up a call
stack (this happens when a catch block catches it, wraps it in another
exception, and rethrows it), I do not log it. I detect this in the
constructor of the exception object by examining the InnerException property
value.

If the exception is thrown by an external module then the catching code must
manually call the exception publish method if it is warranted.

If the exception is crossing a boundary I log it (perhaps again) - this
ensures that exception data is never lost in case the original site that
generated the exception did not log it. You must define what the boundary
is - it can be an appdomain, machine, server, module, etc.

Another thing to look for are cases where an exception gets swallowed. While
this is considered to be "bad" it nonetheless still happens, sometimes
legitimately. We require all such cases to call a method called
SwallowException. Currently it just outputs the exception message to the
trace buffer. I've identified a number of areas in our app where exceptions
were being swallowed that never should have been generated at all.

Server-side applications has more need to log exceptions then client-side
code since they do not have access to a UI to display fault information.
Applications can always make system-wide policy decisions about logging,
unhandled exception policy, etc.

Components (libraries) have a more difficult decision to make since they are
small pieces that do not "own" a logging policy or mechanism. They may not
even have security privileges sufficient to log to a file or create an
eventlog source. If you don't know the environment a component will be used
in you cannot make assumptions about what will be available at runtime. In
this case you should only throw the exception and let the code using the
component make the decision about how to handle the exception.

There currently is no system-wide notification that is generated whenever
any exception is thrown - this is unfortunate because this would be useful
for ensuring that exceptions are always logged.

"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
Hi,

I'm getting into the Trace-functionality in .NET, using it to provide some
much-needed logging across dlls in the project we're working on. However,
being a newbie, I'm wondering if some more experienced loggers can provide
me with some ideas as to how to log in a simple yet flexible manner. For
instance, I'd like the code to be as uncluttered as possible by Trace
statements.

As an example of basic logging functionality, I've come up with some
alternatives for logging exceptions that occur in an object:

1) Wrap the throwing of an exception in a method, which can handle any
logging before throwing the actual exception.

2) Handle logging in the constructors of my own hierarchy of exceptions.
This makes the logging more transparent in the code, but doesn't work for
standard .NET exceptions such as ArgumentNullException (I'd have to subtype it).

3) Use a decorator object to wrap the original object, catch all exceptions, write to log, and rethrow.

Any and all thoughts/comments are much appreciated!

Regards,
Einar

--
"If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -- Lewis Carroll

Nov 16 '05 #4
Thanks for your thoughts, definitely valuable input for developing my own
strategy!

Regards,
Einar
Nov 16 '05 #5
Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read I may
use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
Hi,

I'm getting into the Trace-functionality in .NET, using it to provide some
much-needed logging across dlls in the project we're working on. However,
being a newbie, I'm wondering if some more experienced loggers can provide
me with some ideas as to how to log in a simple yet flexible manner. For
instance, I'd like the code to be as uncluttered as possible by Trace
statements.

As an example of basic logging functionality, I've come up with some
alternatives for logging exceptions that occur in an object:

1) Wrap the throwing of an exception in a method, which can handle any
logging before throwing the actual exception.

2) Handle logging in the constructors of my own hierarchy of exceptions.
This makes the logging more transparent in the code, but doesn't work for
standard .NET exceptions such as ArgumentNullException (I'd have to subtype it).

3) Use a decorator object to wrap the original object, catch all exceptions, write to log, and rethrow.

Any and all thoughts/comments are much appreciated!

Regards,
Einar

--
"If it was so, it might be; and if it were so, it would be; but as it isn't, it ain't. That's logic" -- Lewis Carroll

Nov 16 '05 #6
Hi Jay,

Thanks for the input and the pointer to the article. I think I may have read
it a while ago, but I believe it's worth another look.

There are many issues related to exception handling (obviously), but
handling unhandled exceptions is actually very important to us, as we're
writing an add-in to an existing program. We don't want to bring everything
else down with us... I think the rest of the guys I'm working with should
read the article too.

Thanks again.

Einar

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read I may
use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm raises an exception, the Application.ThreadException handler will catch all uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
Hi,

I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some more experienced loggers can provide me with some ideas as to how to log in a simple yet flexible manner. For
instance, I'd like the code to be as uncluttered as possible by Trace
statements.

As an example of basic logging functionality, I've come up with some
alternatives for logging exceptions that occur in an object:

1) Wrap the throwing of an exception in a method, which can handle any
logging before throwing the actual exception.

2) Handle logging in the constructors of my own hierarchy of exceptions.
This makes the logging more transparent in the code, but doesn't work for standard .NET exceptions such as ArgumentNullException (I'd have to

subtype
it).

3) Use a decorator object to wrap the original object, catch all

exceptions,
write to log, and rethrow.

Any and all thoughts/comments are much appreciated!

Regards,
Einar

--
"If it was so, it might be; and if it were so, it would be; but as it

isn't,
it ain't. That's logic" -- Lewis Carroll


Nov 16 '05 #7
If you want to avoid bringing everything else down then you cannot allow the
exception to be unhandled, especially if you are writing an add-in. You
should wrap all threads that you create in try-catch blocks.

The rules under v1.0 and v1.1 of the runtime are that if the unhandled
exception occurs on the main thread or a thread that originates in unmanaged
code the application will be terminated. You cannot change this - it is
baked into the runtime.

If the unhandled exception occurs on a thread other then this, such as a
threadpool thread, one manually started, or the finalizer thread, then an
unhandled exception event will be sent and the exception will be swallowed.
While the current implementation of the runtime does not terminate an app on
these threads there is no guarantee that this will not change, and in fact
it probably will (and should) change.

There is a flag in the event args that indicates if the app will exit - this
is a readonly indicator of what will happen to the app after the UE handler
has run to completion.

I also disagree conceptually with using the UE handler as the backstop
exception handler. It is convenient to use it that way but I consider it to
be bad practice - I prefer to wrap all threads, etc. in a try-catch, also
using specific try-catches as necessary to locally recover from errors, and
I treat all UEs as a indication that a programming error may have occurred.
I definitely log all that I get but I consider them to be bugs.

I agree with the liberal use of try-finally blocks.

regards,
Dave
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
Hi Jay,

Thanks for the input and the pointer to the article. I think I may have read it a while ago, but I believe it's worth another look.

There are many issues related to exception handling (obviously), but
handling unhandled exceptions is actually very important to us, as we're
writing an add-in to an existing program. We don't want to bring everything else down with us... I think the rest of the guys I'm working with should
read the article too.

Thanks again.

Einar

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read I may
use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when

you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to

the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the

MainForm
raises an exception, the Application.ThreadException handler will catch

all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
Hi,

I'm getting into the Trace-functionality in .NET, using it to provide

some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some more experienced loggers can provide me with some ideas as to how to log in a simple yet flexible manner. For instance, I'd like the code to be as uncluttered as possible by Trace
statements.

As an example of basic logging functionality, I've come up with some
alternatives for logging exceptions that occur in an object:

1) Wrap the throwing of an exception in a method, which can handle any
logging before throwing the actual exception.

2) Handle logging in the constructors of my own hierarchy of exceptions. This makes the logging more transparent in the code, but doesn't work for standard .NET exceptions such as ArgumentNullException (I'd have to

subtype
it).

3) Use a decorator object to wrap the original object, catch all

exceptions,
write to log, and rethrow.

Any and all thoughts/comments are much appreciated!

Regards,
Einar

--
"If it was so, it might be; and if it were so, it would be; but as it

isn't,
it ain't. That's logic" -- Lewis Carroll



Nov 16 '05 #8
Einar,
As David suggests: For information & ideas on exception handling in Add-Ins
see:

http://msdn.microsoft.com/msdnmag/is...10/Plug%2Dins/

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
Hi Jay,

Thanks for the input and the pointer to the article. I think I may have read it a while ago, but I believe it's worth another look.

There are many issues related to exception handling (obviously), but
handling unhandled exceptions is actually very important to us, as we're
writing an add-in to an existing program. We don't want to bring everything else down with us... I think the rest of the guys I'm working with should
read the article too.

Thanks again.

Einar

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eW**************@tk2msftngp13.phx.gbl...
Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read I may
use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when

you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to

the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the

MainForm
raises an exception, the Application.ThreadException handler will catch

all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
Hi,

I'm getting into the Trace-functionality in .NET, using it to provide

some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some more experienced loggers can provide me with some ideas as to how to log in a simple yet flexible manner. For instance, I'd like the code to be as uncluttered as possible by Trace
statements.

As an example of basic logging functionality, I've come up with some
alternatives for logging exceptions that occur in an object:

1) Wrap the throwing of an exception in a method, which can handle any
logging before throwing the actual exception.

2) Handle logging in the constructors of my own hierarchy of exceptions. This makes the logging more transparent in the code, but doesn't work for standard .NET exceptions such as ArgumentNullException (I'd have to

subtype
it).

3) Use a decorator object to wrap the original object, catch all

exceptions,
write to log, and rethrow.

Any and all thoughts/comments are much appreciated!

Regards,
Einar

--
"If it was so, it might be; and if it were so, it would be; but as it

isn't,
it ain't. That's logic" -- Lewis Carroll



Nov 16 '05 #9
Hi David,

Thanks for the input. I'm learning a lot from this.

I agree with your reasoning; however, since there are several developers on
my project, there is no way I can guarantee that the guidelines you're
outlining will actually be followed. I'm not even sure if I can trust myself
all the time. I'm trying to do things the right way, though.

So basically I'm thinking I need to include a UE handler as a last resort,
in order enable some logging that might point in the direction of the weak
code. The reason I'm looking into these things a bit more seriously is that
I've become annoyed with the add-in dying (and taking the main app with it)
with little or no information saying why.

Thanks again,
Einar.
"David Levine" <no****************@wi.rr.com> wrote in message
news:OW*************@TK2MSFTNGP11.phx.gbl...
If you want to avoid bringing everything else down then you cannot allow the exception to be unhandled, especially if you are writing an add-in. You
should wrap all threads that you create in try-catch blocks.

The rules under v1.0 and v1.1 of the runtime are that if the unhandled
exception occurs on the main thread or a thread that originates in unmanaged code the application will be terminated. You cannot change this - it is
baked into the runtime.

If the unhandled exception occurs on a thread other then this, such as a
threadpool thread, one manually started, or the finalizer thread, then an
unhandled exception event will be sent and the exception will be swallowed. While the current implementation of the runtime does not terminate an app on these threads there is no guarantee that this will not change, and in fact
it probably will (and should) change.

There is a flag in the event args that indicates if the app will exit - this is a readonly indicator of what will happen to the app after the UE handler has run to completion.

I also disagree conceptually with using the UE handler as the backstop
exception handler. It is convenient to use it that way but I consider it to be bad practice - I prefer to wrap all threads, etc. in a try-catch, also
using specific try-catches as necessary to locally recover from errors, and I treat all UEs as a indication that a programming error may have occurred. I definitely log all that I get but I consider them to be bugs.

I agree with the liberal use of try-finally blocks.

regards,
Dave
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
Hi Jay,

Thanks for the input and the pointer to the article. I think I may have

read
it a while ago, but I believe it's worth another look.

There are many issues related to exception handling (obviously), but
handling unhandled exceptions is actually very important to us, as we're
writing an add-in to an existing program. We don't want to bring

everything
else down with us... I think the rest of the guys I'm working with should
read the article too.

Thanks again.

Einar

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eW**************@tk2msftngp13.phx.gbl...
Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read I may use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached
to
the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the

MainForm
raises an exception, the Application.ThreadException handler will
catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
> Hi,
>
> I'm getting into the Trace-functionality in .NET, using it to
provide some
> much-needed logging across dlls in the project we're working on.

However,
> being a newbie, I'm wondering if some more experienced loggers can

provide
> me with some ideas as to how to log in a simple yet flexible manner. For > instance, I'd like the code to be as uncluttered as possible by
Trace > statements.
>
> As an example of basic logging functionality, I've come up with some
> alternatives for logging exceptions that occur in an object:
>
> 1) Wrap the throwing of an exception in a method, which can handle any > logging before throwing the actual exception.
>
> 2) Handle logging in the constructors of my own hierarchy of

exceptions. > This makes the logging more transparent in the code, but doesn't work for
> standard .NET exceptions such as ArgumentNullException (I'd have to
subtype
> it).
>
> 3) Use a decorator object to wrap the original object, catch all
exceptions,
> write to log, and rethrow.
>
> Any and all thoughts/comments are much appreciated!
>
> Regards,
> Einar
>
> --
> "If it was so, it might be; and if it were so, it would be; but as

it isn't,
> it ain't. That's logic" -- Lewis Carroll
>
>



Nov 16 '05 #10
Hi Jay,

Thanks for the reference, I'll do some reading this afternoon :-)

Regards,
Einar

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Einar,
As David suggests: For information & ideas on exception handling in Add-Ins see:

http://msdn.microsoft.com/msdnmag/is...10/Plug%2Dins/

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
Hi Jay,

Thanks for the input and the pointer to the article. I think I may have

read
it a while ago, but I believe it's worth another look.

There are many issues related to exception handling (obviously), but
handling unhandled exceptions is actually very important to us, as we're
writing an add-in to an existing program. We don't want to bring

everything
else down with us... I think the rest of the guys I'm working with should
read the article too.

Thanks again.

Einar

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:eW**************@tk2msftngp13.phx.gbl...
Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read I may use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached
to
the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the

MainForm
raises an exception, the Application.ThreadException handler will
catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
> Hi,
>
> I'm getting into the Trace-functionality in .NET, using it to
provide some
> much-needed logging across dlls in the project we're working on.

However,
> being a newbie, I'm wondering if some more experienced loggers can

provide
> me with some ideas as to how to log in a simple yet flexible manner. For > instance, I'd like the code to be as uncluttered as possible by
Trace > statements.
>
> As an example of basic logging functionality, I've come up with some
> alternatives for logging exceptions that occur in an object:
>
> 1) Wrap the throwing of an exception in a method, which can handle any > logging before throwing the actual exception.
>
> 2) Handle logging in the constructors of my own hierarchy of

exceptions. > This makes the logging more transparent in the code, but doesn't work for
> standard .NET exceptions such as ArgumentNullException (I'd have to
subtype
> it).
>
> 3) Use a decorator object to wrap the original object, catch all
exceptions,
> write to log, and rethrow.
>
> Any and all thoughts/comments are much appreciated!
>
> Regards,
> Einar
>
> --
> "If it was so, it might be; and if it were so, it would be; but as

it isn't,
> it ain't. That's logic" -- Lewis Carroll
>
>



Nov 16 '05 #11
how exactly do you do this on windows services? i am tracking a
filesystemwatcher problem that is looking more and more like a framework
bug, but i can only get very little detail and it kills my service. i
specified the AppDomain.UnhandledException handler in my service main
function, but its still not catching this error that keeps popping up.
Message by Jay B. Harlow [MVP - Outlook] <Ja************@msn.com> on: 7/9/2004 10:58:48 AM
Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read I may
use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
Hi,

I'm getting into the Trace-functionality in .NET, using it to provide some
much-needed logging across dlls in the project we're working on. However,
being a newbie, I'm wondering if some more experienced loggers can provide
me with some ideas as to how to log in a simple yet flexible manner. For
instance, I'd like the code to be as uncluttered as possible by Trace
statements.

As an example of basic logging functionality, I've come up with some
alternatives for logging exceptions that occur in an object:

1) Wrap the throwing of an exception in a method, which can handle any
logging before throwing the actual exception.

2) Handle logging in the constructors of my own hierarchy of exceptions.
This makes the logging more transparent in the code, but doesn't work for
standard .NET exceptions such as ArgumentNullException (I'd have to

subtype
it).

3) Use a decorator object to wrap the original object, catch all

exceptions,
write to log, and rethrow.

Any and all thoughts/comments are much appreciated!

Regards,
Einar

--
"If it was so, it might be; and if it were so, it would be; but as it

isn't,
it ain't. That's logic" -- Lewis Carroll


Nov 16 '05 #12
You don't want app domain stuff usless your are creating app domains.
Just use Application.ThreadException... something like below... sample
class attached.

CustomExceptionHandler eh = new CustomExceptionHandler();
Application.ThreadException += new ThreadExceptionEventHandler(
eh.OnThreadException );

Best,
/jhd

p.s. timers, filesyswatchers are all different processes... need
semaphores vs monitor/lock

Steel City Phantom wrote:
how exactly do you do this on windows services? i am tracking a
filesystemwatcher problem that is looking more and more like a framework
bug, but i can only get very little detail and it kills my service. i
specified the AppDomain.UnhandledException handler in my service main
function, but its still not catching this error that keeps popping up.
Message by Jay B. Harlow [MVP - Outlook] <Ja************@msn.com> on: 7/9/2004 10:58:48 AM
Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read I may
use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
Hi,

I'm getting into the Trace-functionality in .NET, using it to provide some
much-needed logging across dlls in the project we're working on. However,
being a newbie, I'm wondering if some more experienced loggers can provide
me with some ideas as to how to log in a simple yet flexible manner. For
instance, I'd like the code to be as uncluttered as possible by Trace
statements.

As an example of basic logging functionality, I've come up with some
alternatives for logging exceptions that occur in an object:

1) Wrap the throwing of an exception in a method, which can handle any
logging before throwing the actual exception.

2) Handle logging in the constructors of my own hierarchy of exceptions.
This makes the logging more transparent in the code, but doesn't work for
standard .NET exceptions such as ArgumentNullException (I'd have to


subtype
it).

3) Use a decorator object to wrap the original object, catch all


exceptions,
write to log, and rethrow.

Any and all thoughts/comments are much appreciated!

Regards,
Einar

--
"If it was so, it might be; and if it were so, it would be; but as it


isn't,
it ain't. That's logic" -- Lewis Carroll


/// <summary>
/// Top level exception handler. Future home of automatic bug report form and add to bug database.
/// </summary>
internal class CustomExceptionHandler
{
// Handles the exception event.
public void OnThreadException( object sender, ThreadExceptionEventArgs t )
{
DialogResult result = DialogResult.Cancel;
try
{
result = this.ShowThreadExceptionDialog( t.Exception );
}
catch
{
try
{
MessageBox.Show( "Fatal Error", "Fatal Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop );
}
finally
{
Application.Exit();
}
}

// Exits the program when the user clicks Abort.
if( result == DialogResult.Abort )
Application.Exit();
}

// Creates the error message and displays it.
private DialogResult ShowThreadExceptionDialog( Exception e )
{
string errorMsg = "An error occurred please contact the adminstrator with the following information:\n\n";
errorMsg = errorMsg + e.Message + "\n\nStack Trace:\n" + e.StackTrace;
return MessageBox.Show( errorMsg, "Application Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop );
}
}
Nov 16 '05 #13
clarification... System.Windows.Forms.Application.ThreadException.. . per
Jay's reply. I don't think it's winform specific... just where it lives.

/jhd

Dhominator wrote:
You don't want app domain stuff usless your are creating app domains.
Just use Application.ThreadException... something like below... sample
class attached.

CustomExceptionHandler eh = new CustomExceptionHandler();
Application.ThreadException += new ThreadExceptionEventHandler(
eh.OnThreadException );

Best,
/jhd

p.s. timers, filesyswatchers are all different processes... need
semaphores vs monitor/lock

Steel City Phantom wrote:
how exactly do you do this on windows services? i am tracking a
filesystemwatcher problem that is looking more and more like a framework
bug, but i can only get very little detail and it kills my service. i
specified the AppDomain.UnhandledException handler in my service main
function, but its still not catching this error that keeps popping up.
Message by Jay B. Harlow [MVP - Outlook] <Ja************@msn.com> on:
7/9/2004 10:58:48 AM
Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read
I may
use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your
app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why &
when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached
to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the
MainForm
raises an exception, the Application.ThreadException handler will
catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...

Hi,

I'm getting into the Trace-functionality in .NET, using it to
provide some
much-needed logging across dlls in the project we're working on.
However,
being a newbie, I'm wondering if some more experienced loggers can
provide
me with some ideas as to how to log in a simple yet flexible manner.
For
instance, I'd like the code to be as uncluttered as possible by Trace
statements.

As an example of basic logging functionality, I've come up with some
alternatives for logging exceptions that occur in an object:

1) Wrap the throwing of an exception in a method, which can handle any
logging before throwing the actual exception.

2) Handle logging in the constructors of my own hierarchy of
exceptions.
This makes the logging more transparent in the code, but doesn't
work for
standard .NET exceptions such as ArgumentNullException (I'd have to
subtype

it).

3) Use a decorator object to wrap the original object, catch all
exceptions,

write to log, and rethrow.

Any and all thoughts/comments are much appreciated!

Regards,
Einar

--
"If it was so, it might be; and if it were so, it would be; but as it
isn't,

it ain't. That's logic" -- Lewis Carroll


------------------------------------------------------------------------

/// <summary>
/// Top level exception handler. Future home of automatic bug report form and add to bug database.
/// </summary>
internal class CustomExceptionHandler
{
// Handles the exception event.
public void OnThreadException( object sender, ThreadExceptionEventArgs t )
{
DialogResult result = DialogResult.Cancel;
try
{
result = this.ShowThreadExceptionDialog( t.Exception );
}
catch
{
try
{
MessageBox.Show( "Fatal Error", "Fatal Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop );
}
finally
{
Application.Exit();
}
}

// Exits the program when the user clicks Abort.
if( result == DialogResult.Abort )
Application.Exit();
}

// Creates the error message and displays it.
private DialogResult ShowThreadExceptionDialog( Exception e )
{
string errorMsg = "An error occurred please contact the adminstrator with the following information:\n\n";
errorMsg = errorMsg + e.Message + "\n\nStack Trace:\n" + e.StackTrace;
return MessageBox.Show( errorMsg, "Application Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop );
}
}

Nov 16 '05 #14
I'd be careful thinking that way. OnThreadException is based around a message
loop
and the exception being raised is from within a call-stack where the message
loop is
somewhere lower. In some cases I believe there may be more hook-up going on,
but not quite sure.

Maybe you should check out AppDomain.UnhandledException
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Dhominator" <a@b.c> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
clarification... System.Windows.Forms.Application.ThreadException.. . per Jay's
reply. I don't think it's winform specific... just where it lives.

/jhd

Dhominator wrote:
You don't want app domain stuff usless your are creating app domains. Just
use Application.ThreadException... something like below... sample class
attached.

CustomExceptionHandler eh = new CustomExceptionHandler();
Application.ThreadException += new ThreadExceptionEventHandler(
eh.OnThreadException );

Best,
/jhd

p.s. timers, filesyswatchers are all different processes... need semaphores
vs monitor/lock

Steel City Phantom wrote:
how exactly do you do this on windows services? i am tracking a
filesystemwatcher problem that is looking more and more like a framework
bug, but i can only get very little detail and it kills my service. i
specified the AppDomain.UnhandledException handler in my service main
function, but its still not catching this error that keeps popping up.
Message by Jay B. Harlow [MVP - Outlook] <Ja************@msn.com> on:
7/9/2004 10:58:48 AM

Einar,
In addition to the other comments about using the Exception Management
Block, I normally do my logging in a global exception handler. (Read I may
use the Exception Management Block in my Global Exception Handler)

Also I use try/finally & using more then I use try/catch. I only use
try/catch when there is something specific that I need to do with the
exception, otherwise I let my global exception handlers handle the
exception.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when
you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to
the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the
MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.

Hope this helps
Jay
"Einar Høst" <_e*******@hotmail.com> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...

> Hi,
>
> I'm getting into the Trace-functionality in .NET, using it to provide some
> much-needed logging across dlls in the project we're working on. However,
> being a newbie, I'm wondering if some more experienced loggers can provide
> me with some ideas as to how to log in a simple yet flexible manner. For
> instance, I'd like the code to be as uncluttered as possible by Trace
> statements.
>
> As an example of basic logging functionality, I've come up with some
> alternatives for logging exceptions that occur in an object:
>
> 1) Wrap the throwing of an exception in a method, which can handle any
> logging before throwing the actual exception.
>
> 2) Handle logging in the constructors of my own hierarchy of exceptions.
> This makes the logging more transparent in the code, but doesn't work for
> standard .NET exceptions such as ArgumentNullException (I'd have to
subtype

> it).
>
> 3) Use a decorator object to wrap the original object, catch all
exceptions,

> write to log, and rethrow.
>
> Any and all thoughts/comments are much appreciated!
>
> Regards,
> Einar
>
> --
> "If it was so, it might be; and if it were so, it would be; but as it
isn't,

> it ain't. That's logic" -- Lewis Carroll
>
>

------------------------------------------------------------------------

/// <summary>
/// Top level exception handler. Future home of automatic bug report form and
add to bug database.
/// </summary>
internal class CustomExceptionHandler
{
// Handles the exception event.
public void OnThreadException( object sender, ThreadExceptionEventArgs t )
{
DialogResult result = DialogResult.Cancel;
try
{
result = this.ShowThreadExceptionDialog( t.Exception );
}
catch
{
try
{
MessageBox.Show( "Fatal Error", "Fatal Error",
MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop );
}
finally
{
Application.Exit();
}
}

// Exits the program when the user clicks Abort.
if( result == DialogResult.Abort )
Application.Exit();
}

// Creates the error message and displays it.
private DialogResult ShowThreadExceptionDialog( Exception e )
{
string errorMsg = "An error occurred please contact the adminstrator with the
following information:\n\n";
errorMsg = errorMsg + e.Message + "\n\nStack Trace:\n" + e.StackTrace;
return MessageBox.Show( errorMsg, "Application Error",
MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop );
}
}

Nov 16 '05 #15
your right, but the appdomain doesn't catch it and the application puts
it in an infinate loop.

now what.

Message by Justin Rogers <Ju****@games4dotnet.com> on: 11/4/2004 4:21:21 PM
I'd be careful thinking that way. OnThreadException is based around a message
loop
and the exception being raised is from within a call-stack where the message
loop is
somewhere lower. In some cases I believe there may be more hook-up going on,
but not quite sure.

Maybe you should check out AppDomain.UnhandledException
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Dhominator" <a@b.c> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl.. .
clarification... System.Windows.Forms.Application.ThreadException.. . per Jay's
reply. I don't think it's winform specific... just where it lives.

/jhd

Dhominator wrote:
You don't want app domain stuff usless your are creating app domains. Just
use Application.ThreadException... something like below... sample class
attached.

CustomExceptionHandler eh = new CustomExceptionHandler();
Application.ThreadException += new ThreadExceptionEventHandler(
eh.OnThreadException );

Best,
/jhd

p.s. timers, filesyswatchers are all different processes... need semaphores
vs monitor/lock

Steel City Phantom wrote:

how exactly do you do this on windows services? i am tracking a
filesystemwatcher problem that is looking more and more like a framework
bug, but i can only get very little detail and it kills my service. i
specified the AppDomain.UnhandledException handler in my service main
function, but its still not catching this error that keeps popping up.
Message by Jay B. Harlow [MVP - Outlook] <Ja************@msn.com> on:
7/9/2004 10:58:48 AM

> Einar,
> In addition to the other comments about using the Exception Management
> Block, I normally do my logging in a global exception handler. (Read I may
> use the Exception Management Block in my Global Exception Handler)
>
> Also I use try/finally & using more then I use try/catch. I only use
> try/catch when there is something specific that I need to do with the
> exception, otherwise I let my global exception handlers handle the
> exception.
>
> Depending on the type of application you are creating, .NET has three
> different global exception handlers.
>
> For ASP.NET look at:
> System.Web.HttpApplication.Error event
> Normally placed in your Global.asax file.
>
> For console applications look at:
> System.AppDomain.UnhandledException event
> Use AddHandler in your Sub Main.
>
> For Windows Forms look at:
> System.Windows.Forms.Application.ThreadException event
> Use AddHandler in your Sub Main.
>
> It can be beneficial to combine the above global handlers in your app, as
> well as wrap your Sub Main in a try catch itself.
>
> There is an article in the June 2004 MSDN Magazine that shows how to
> implement the global exception handling in .NET that explains why & when
> you
> use multiple of the above handlers...
>
> http://msdn.microsoft.com/msdnmag/is...T/default.aspx
>
> For example: In my Windows Forms apps I would have a handler attached to
> the
> Application.ThreadException event, plus a Try/Catch in my Main. The
> Try/Catch in Main only catches exceptions if the constructor of the
> MainForm
> raises an exception, the Application.ThreadException handler will catch all
> uncaught exceptions from any form/control event handlers.
>
> Hope this helps
> Jay
>
>
> "Einar Høst" <_e*******@hotmail.com> wrote in message
> news:uw**************@tk2msftngp13.phx.gbl...
>
>> Hi,
>>
>> I'm getting into the Trace-functionality in .NET, using it to provide some
>> much-needed logging across dlls in the project we're working on. However,
>> being a newbie, I'm wondering if some more experienced loggers can provide
>> me with some ideas as to how to log in a simple yet flexible manner. For
>> instance, I'd like the code to be as uncluttered as possible by Trace
>> statements.
>>
>> As an example of basic logging functionality, I've come up with some
>> alternatives for logging exceptions that occur in an object:
>>
>> 1) Wrap the throwing of an exception in a method, which can handle any
>> logging before throwing the actual exception.
>>
>> 2) Handle logging in the constructors of my own hierarchy of exceptions.
>> This makes the logging more transparent in the code, but doesn't work for
>> standard .NET exceptions such as ArgumentNullException (I'd have to
>
>
> subtype
>
>> it).
>>
>> 3) Use a decorator object to wrap the original object, catch all
>
>
> exceptions,
>
>> write to log, and rethrow.
>>
>> Any and all thoughts/comments are much appreciated!
>>
>> Regards,
>> Einar
>>
>> --
>> "If it was so, it might be; and if it were so, it would be; but as it
>
>
> isn't,
>
>> it ain't. That's logic" -- Lewis Carroll
>>
>>
>
>
>
------------------------------------------------------------------------

/// <summary>
/// Top level exception handler. Future home of automatic bug report form and
add to bug database.
/// </summary>
internal class CustomExceptionHandler
{
// Handles the exception event.
public void OnThreadException( object sender, ThreadExceptionEventArgs t )
{
DialogResult result = DialogResult.Cancel;
try
{
result = this.ShowThreadExceptionDialog( t.Exception );
}
catch
{
try
{
MessageBox.Show( "Fatal Error", "Fatal Error",
MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop );
}
finally
{
Application.Exit();
}
}

// Exits the program when the user clicks Abort.
if( result == DialogResult.Abort )
Application.Exit();
}

// Creates the error message and displays it.
private DialogResult ShowThreadExceptionDialog( Exception e )
{
string errorMsg = "An error occurred please contact the adminstrator with the
following information:\n\n";
errorMsg = errorMsg + e.Message + "\n\nStack Trace:\n" + e.StackTrace;
return MessageBox.Show( errorMsg, "Application Error",
MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop );
}
}


Nov 16 '05 #16
Steel City Phantom,
In my windows service I normally wrap each "event" in a Try Catch & log the
exception in the Catch block. My Windows Service is based on a single
System.Timers.Timer, so its a simply matter of wrapping the Timer.Elapsed
handler in a Try/Catch.

I initially expected Timer.Elapsed to raise the AppDomain.UnhandledException
if it had an unhandled exception, however it currently is not working as I
would expect & I have not researched why not.

My Timer.Elapsed also uses ThreadPool.QueueUserWorkItem, The routine passed
is also wrapped in a Try/Catch so I'm not sure if QueueUserWorkItem uses
AppDomain.UnhandledException or not. I have not taken the time to research
ThreadPool & Unhandled Exceptions...

Hope this helps
Jay
"Steel City Phantom" <sc******@yaright.com> wrote in message
news:e2**************@TK2MSFTNGP11.phx.gbl...
your right, but the appdomain doesn't catch it and the application puts
it in an infinate loop.

now what.

Message by Justin Rogers <Ju****@games4dotnet.com> on: 11/4/2004 4:21:21
PM
I'd be careful thinking that way. OnThreadException is based around a
message
loop
and the exception being raised is from within a call-stack where the
message
loop is
somewhere lower. In some cases I believe there may be more hook-up going
on,
but not quite sure.

Maybe you should check out AppDomain.UnhandledException

<<snip>>
Nov 16 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeremy Fincher | last post by:
I've just converted my application to use the logging module for its logging needs (it's quite excellent, actually :)). One thing I still have to resolve, though: in many places in my application,...
6
by: Kevin Jackson | last post by:
Let's say we log exceptions to the windows application event log using the Exception Management Application Block. Is there a pattern that can be used so the exception is logged only once and not...
6
by: Ali-R | last post by:
I'm using a .Net application to execute DTS packages within Sqlserver,I need to have very customizable and powerful Exception maangement systems which loggs different issues happend in the DTS...
1
by: BobLaughland | last post by:
Hi All, I am development an ASP .NET C# web site. Just wondering the best way to implement logging on my web site. (I have a logging class to log database access, exceptions, etc, etc). I...
17
by: Cramer | last post by:
I plan to implement an exception logging feature in an ASP.NET Web application that writes encountered exceptions to disk. The exception data will be stored as XML. I am planning on having each...
4
by: Alexandru Mosoi | last post by:
why doesn't logging throw any exception when it should? how do I configure logging to throw exceptions? .... logging.fatal('asdf %d', '123') .... except: .... print 'this line is never...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.