Topic: Handle common conditions without throwing exceptions try or catch
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();
}
Author: GANI MALLA
Topic Replies (0)