Exception Handling in C#

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

I am after some advice on the best approach to passing
exceptions through the layers of my application.

Rather than placing try/catch statements in my data,
business & UI layers I have hooked up a
ThreadExceptionEventHandler event to act upon any
exceptions in any of the methods invoked. This way I can
determine the exception via the ThreadExceptionEventArgs
Exception.GetType() method and perform the necessary
application logic.

Has anyone got any information about using this or any
other approach regarding passing exception information up
through the call stack.

Regards

Mike
 
I'd tend to think that having a handler hooked up would be less clear than
using explicit try/catches where needed. Depending on the app, you might
want to let things bubble up directly, or at each tier define your own
exceptions and throw them.

But I definately thing you should have try/catch/finally blocks inline in
your code instead of hiding somewhere else. It'll be easier to recover and
continue that way.

-mike
MVP
 
But I definately thing you should have try/catch/finally blocks inline in
your code instead of hiding somewhere else. It'll be easier to recover and
continue that way.

Agreed.
 
I think it would be easier to catch exceptions if you stick to the try-catch- blocks
Saludos
 
Back
Top