When catching an exception on a database reading/writing operation, what specific exceptions should I try to catch in a Try-Catch construction?
try
{
MyDatabaseHandlingMethod();
}
catch (exception ex)//what to use instead of just "exception"?
{
//except开发者_开发百科ion handling
}
What are those exceptions to use instead of just "exception" in case of trying to perform a database related operation? (like IOException
in case of file handling operations)
SQL Server exceptions will be of type SqlException
- they contain an Errors
collection that holds a list of SqlError
objects that contain the detailed information about the exception.
For reference see MSDN:
- System.Data.SqlClient.SqlException
- System.Data.SqlClient.SqlError
You probably need to handle SqlException that has Number
property.
精彩评论