Normally, I surround my Dataset/fill or DBreader execut with a try/Catch.
Something like:
************************************************** ****
Dim dbReader As SqlDataReader
Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSet tings("MM_CONNECTION_STRING_Connection")
Dim objConn as New SqlConnection (ConnectionString)
Dim CommandText as String = "Select City,StateCode from zipCodes where
zipCode = @ZipCode and CityType = 'D'"
Dim objCmd as New SqlCommand(CommandText,objConn)
with objCmd.Parameters
.Add("@ZipCode",SqlDbType.VarChar,9).value = ZipCode.Text
end with
try
objConn.Open()
dbReader = objCmd.ExecuteReader
if dbReader.Read then
City.Text = dbReader("City")
State.Text = dbReader("StateCode")
end if
catch ex as Exception
... Do something
finally
objConn.Close()
end try
************************************************** ************
I have someone here that writes his code where he surround all his code with
a try/catch, not just the area where he could logically expect to have a
problem. Sometimes he would surround all the code in one try/catch block
and nest another around the Sql section.
His reasoning is that if he gets an error, he wants to keep the user on a
page and give an error there instead of having it go to some general page.
I was curious about other ideas on this on whether this is a good ideas.
Just trying to get some pros and cons.
Thanks,
Tom