473,513 Members | 2,669 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception handling architecture

Hi All,
I have am working on C# 2.0 for a project and need to know the best
practices for exception handling.
At the moment I am doing it as Follows.

I have a Manager class that is supposed to update entries in the Dictionary
and Database as well, to separate DataBase Layer I have written another
library that contains static methods and does some updating in data base..

The thing I want to know is that is it something that is the right way ? if
not please fuide me with resources...
its like
class PokerTableManager
{

Dictionary<string, PokerTable> PokerTablesDictionary;
public CreateTable(TableInfo info)
{
try
{
PokerTable table = new PokerTable(info);
PokerTablesDictionary.Add("abc",table );

}

}

}

classs PokerTableDAL
{
public static UpdateTable(TableInfo info)
{
try
{
/// SQL Commands here

}
catch(SqlException exp)
{
throw new DataBaseConnectoinException("UNable to connect
to database database",exp)
}

}

public class DataBaseConnectionException : Exception
{
public DataBaseConnectionException()
: base()
{ }
public DataBaseConnectionException(string message)
: base(message)
{ }
public DataBaseConnectionException(string message, Exception inner)
: base(message, inner)
{ }
}
regards

Aftab Alam

Nov 17 '05 #1
1 2046

aftab Alam wrote:
Hi All,
I have am working on C# 2.0 for a project and need to know the best
practices for exception handling.
At the moment I am doing it as Follows.

I have a Manager class that is supposed to update entries in the Dictionary
and Database as well, to separate DataBase Layer I have written another
library that contains static methods and does some updating in data base..

The thing I want to know is that is it something that is the right way ? if
not please fuide me with resources...
its like
class PokerTableManager
{

Dictionary<string, PokerTable> PokerTablesDictionary;
public CreateTable(TableInfo info)
{
try
{
PokerTable table = new PokerTable(info);
PokerTablesDictionary.Add("abc",table );

}

}

}

A try block must have at least one catch block or a finally block. The
code will not compile as is. Do you absolutely need the
try-catch-finally construct here anyway?
classs PokerTableDAL
{
public static UpdateTable(TableInfo info)
{
try
{
/// SQL Commands here

}
catch(SqlException exp)
{
throw new DataBaseConnectoinException("UNable to connect
to database database",exp)
}

}

When working with database connections I recommend either putting the
connection object in a using block or closing the connection in a
finally block. The code above could leave a connection open. Also, I
don't see a need for throwing a new exception after a SqlException has
been caught. Though, at least you've made the SqlException an inner
exception to the new exception.
public class DataBaseConnectionException : Exception
{
public DataBaseConnectionException()
: base()
{ }
public DataBaseConnectionException(string message)
: base(message)
{ }
public DataBaseConnectionException(string message, Exception inner)
: base(message, inner)
{ }
}

Again, I don't see a need for DataBaseConnectionException. Other than
a new class name it isn't providing you with anything new.

regards

Aftab Alam


Nov 17 '05 #2

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

Similar topics

10
3127
by: Bill Davidson | last post by:
Hi there, Please forgive me for posting this article on multiple groups. Being new in the newsgroups, I was not sure which group would have been appropriate for my question. Sorry. My...
1
1830
by: Abelardo Vacca | last post by:
Hello, I am currently in the process of switching our application to a N-Tier model with .NET. One of the aspects we want ot get right from the start not to worry about it after is the...
28
12050
by: dcrespo | last post by:
Hi all, How can I get a raised exception from other thread that is in an imported module? For example: --------------- programA.py ---------------
7
1786
by: Dan Bass | last post by:
In a somewhat complex application, I've developed plug-in architecture and am having a problem as to when to catch general exceptions for logging purposes. In each plug-in class library, for...
44
4162
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...
13
2297
by: tolisss | last post by:
Hi i have setup a global exception handler b4 Application.Run like Application.ThreadException += new ThreadExceptionEventHandler(GlobalExceptionProcessing.AppThreadException ); then after...
2
5861
by: Rajeev Soni | last post by:
Hi, Considering the scenario for handling exceptions in Web Application where we have Presentation layer, Business layer and Data Access layer; if there any exception is occurred in DAL, what is...
1
258
by: Jon | last post by:
Can someone point me to a best practices for exception handling in .Net 2? We have a method that we like for ASP.Net apps on .Net 1.1, but are just moving to 2.0 with winforms apps. Is it still...
1
1447
by: Jarsinio | last post by:
I have some doubts about how managed exception in a VB.net aplication. In my aplicattion I have 3 clases: One clase is the UI ( Windows Forms). This class call a second clase who perform an...
0
7257
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
7157
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
7535
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...
0
7521
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.