John,
We need to make the distinction between Business Logic and Exceptions here.
if program flow does go into your Catch block, that's because you have an
exception - which is NOT a normal, expected part of the business logic. The
best way to avoid this is to test for whatever business conditions might
cause an exception first, and handle them appropriately BEFORE program flow
ends up in a catch block with an exception.
Failing that , you COULD call a separate method from inside your catch block
after whatever "Tests" you need to do dictate that you should do so. And,
that method might very well make additional SQL calls.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"John" wrote:
Hi,
I use try, catch and finallay to control Sql connection, and run into 1
problem. Some of the sql errors, I don't want the program flow to go to
catch block.
Here is my code snippet:
SqlConnection objSqlConn;
objSqlConn = new SqlConnection(strConnectionString);
try
{
objSqlConn.Open();
//Some SQL statements, if errors go to catch block
//Other SQL statements, if errors DO NOT go to catch block
}
catch(SqlException e)
{
//Do error handling here
}
finally
{
objSqlConn.Close();
}
How do I make it happen?
TIA