473,378 Members | 1,504 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,378 software developers and data experts.

Tricky exception handling

Does anyone know best practices (i.e. a tried and true method) for
this problem? I want to re-attempt an operation which caused on
exception, and do so an arbitrary number of times. For example, I
want to try connecting to a database multiple times before giving
up.

I have a solution (in C#), but I suspect it's not the best way to do
it :

RETRY:
try
{
dbAdapter.Fill(dataSetToFill,
statementCriteria.TableName);
}
catch (System.Data.Odbc.OdbcException dbe)
{
x++;
if (x>max)
{
throw new DMTException("************** ODBC
Error >>>" + x.ToString(), dbe);
}
else
{
goto RETRY;
}
}
This seems to work, but I'm using goto,
which is never a good idea.

Any suggestions?
*---------------------------------*
Posted at: http://www.GroupSrv.com
Check: http://wwww.HotCodecs.com
*---------------------------------*

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jul 21 '05 #1
1 1005
Elp
On 27 Jan 2005 10:53:06 -0600, Quimbly wrote:
Does anyone know best practices (i.e. a tried and true method) for
this problem? I want to re-attempt an operation which caused on
exception, and do so an arbitrary number of times. For example, I
want to try connecting to a database multiple times before giving
up.


Why not simply use a while loop:

bool done = false;
while (!done)
{
try
{
// Do something
done = true;
}
catch
{
x++;
if (x>max)
{
// Throw your custom exception
}
}
}
Jul 21 '05 #2

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

Similar topics

3
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
13
by: Steve Jorgensen | last post by:
== On Error Resume next, and Err.Number == If you want to call one of your procedures from another procedure, and check for errors afterward, you mayimagine that you should write code something...
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...
1
by: Quimbly | last post by:
Does anyone know best practices (i.e. a tried and true method) for this problem? I want to re-attempt an operation which caused on exception, and do so an arbitrary number of times. For example,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.