473,320 Members | 2,054 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,320 software developers and data experts.

Exception Hanlding

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
Nov 15 '05 #1
2 2570
MS has published some guidelines:

..NET Framework General Reference
Error Raising and Handling Guidelines
http://tinyurl.com/2opdo

--
Greetz,
Jan
__________________________________
Read my weblog: http://weblogs.asp.net/jan
"tom" <to*@cce.coom> schreef in bericht
news:Oy*************@TK2MSFTNGP10.phx.gbl...
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

Nov 15 '05 #2
Hi tom,

"tom" <to*@cce.coom> wrote in message
news:Oy*************@TK2MSFTNGP10.phx.gbl...
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
Nov 15 '05 #3

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

Similar topics

4
by: Nicolas Fleury | last post by:
Hi, I've made a small utility to re-raise an exception with the same stack as before with additional information in it. Since I want to keep the same exception type and that some types have very...
2
by: cody | last post by:
Is this good style? I always have to catch the generic System.Exception because our system supports nested transactions that is BeginTransaction increases the level, Commit decreases it, rollback...
1
by: Old Wolf | last post by:
1. What is the difference between #include <stdexcept> and #include <exception> ? 2. Is there a list somewhere of what each standard exception is used for? either to throw them, or throw...
3
by: Franz | last post by:
try { } catch (ExceptionA A) { XXXXXXXXXXXXX } catch (ExceptionB B) { XXXXXXXXXXXXX
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
3
by: JohnDeHope3 | last post by:
First let me say that I understand that Asp.Net wraps my exception in an HttpUnhandledException. I have found a lot of discussion about that on the web, which was informative, but not helpful. Let...
2
by: Darko Miletic | last post by:
Recently I wrote a dll in c++ and to simplify the distribution I decided to link with multithreaded static library (/MT or /MTd option). In debug everything works fine but in release I get this: ...
8
by: Nayna | last post by:
how to rethrown an exception in java?
10
by: dinopc | last post by:
Hello, i am italian, I apologize for my English. I would like to extend the class std::exception: #include <iostream.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.