1

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"?
{
    //exception 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)

1

2 Answers 2

2

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:

Sign up to request clarification or add additional context in comments.

Comments

1

You probably need to handle SqlException that has Number property.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.