Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"SQLException" or "Exception"

Status
Not open for further replies.

vcllvc

Programmer
Jul 12, 2001
136
US
Should I catche a "SQLException" or an "Exception" while filling a dataset?

 
if you catch SQLExceptions, any other type of exception will go unhandled. You really only need to handle the SQL excpetion if it has info you need that the exception doesn't (I havent had this problem since the Excpetion has always had all the info i needed to find the problem)

But if you want to get really fancy, you can catch BOTH types of exceptions. You do this by declaring two catch blocks, one with each exception type. When an error gets raised, the catch block with the appropriate exception will get fired, for example:

Code:
try
{
     // some sql code here...
}
catch(SqlException se)
{
     // Handle SQL Exception here...
     MessageBox.Show("SQL Exception occurred");
}
catch(Exception e)
{
     // Some non sql exception happened...
     MessageBox.Show("Unknown Exception occurred");
}
 
The MSDN documentation falls down here a little bit. They normally tell you what exceptions can possibly be thrown.

I traced it all the back to IDbCommand.ExecuteReader, and none of the intervening classes or methods say what exceptions they throw.

So, just do as NeilTrain suggests.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top