Exception Hanlding

T

tom

Hi,

I am developing a WinForm application and I am looking for a guide on where
to place Exception Handling. My application is designed into three tiers
UI, Business Objects, and Data Access Layer. My questions is where should I
put exception handling:

1) Should it be put in all significant methods in all layers?
2) Should I create an exception base class that will handle the errors and
pass useful error messages to the user?
3) Can I get away with just putting exception handling in the UI process
components which will then throw the error to the base class?

Thanks
 
D

Daniel Pratt

Hi tom,

tom said:
Hi,

I am developing a WinForm application and I am looking for a guide on where
to place Exception Handling. My application is designed into three tiers
UI, Business Objects, and Data Access Layer. My questions is where should I
put exception handling:

1) Should it be put in all significant methods in all layers?
2) Should I create an exception base class that will handle the errors and
pass useful error messages to the user?
3) Can I get away with just putting exception handling in the UI process
components which will then throw the error to the base class?

Regarding exception handling in the Business Objects and Data Access
Layer:

1. If know you can recover gracefully from an exception, catch it
and deal with it.
2. If you can't (or don't want to) recover from the exception in
that layer, but there is some information you can pass up that's relevant to
the exception, catch the original exception and throw your custom exception.
Make sure to reference the original exception as the InnerException.
3. Otherwise, don't catch the exception

Regarding exception handling in the UI layer:
1. If you know you can recover from an exception, catch it and deal
with it. Display messages to the user as appropriate.
2. If you don't know how to handle an exception, don't catch it.
3. Optionally, attach an event handler to
Application.ThreadException to display a custom message to the user letting
them know something unexpected happened and maybe giving them some basic
options on what to do about it (continue, quit, send e-mail containing
exception info, etc.).

MS's Exception Management Block is useful for logging application
exceptions:
http://tinyurl.com/lhbd

My $0.02.

Regards,
Dan
 

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