Topic:   Handle common conditions without throwing exceptions try or catch
May 12, 2022 14:10 1 Replies 3876 Views GANI MALLA

Consider handling them in a way that will avoid the exception. For example, if we try to close a connection that is already closed, then get an InvalidOperationException. We can avoid that by using an if statement to check the connection state before trying to close it.

C#

if (conn.State != ConnectionState.Closed)

{

conn.Close();

}

Prev Next
Topic Replies (1)
Leave a Reply
Guest User

Not sure what solution is right for you?

Choose the right one for you.
Get the help of the experts and find a solution that best suits your needs.


Let`s Connect