Topic:   Handle common conditions without throwing exceptions try or catch
May 12, 2022 14:10 0 Replies 145 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 (0)
Leave a Reply
Guest User

Not sure whare to join tuition 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