C
Carol
Exception may be thrown in the code inside the try block.
I want to handling the SqlException with State == 1 in a special way,
and for all others I want to use a general way to handle. Which of the
following options is better?
-----------------------------------------------------
Option 1:
try{...}
catch (System.Data.SqlClient.SqlException ex)
{
if (ex.State == 1)
{
// special error handling
}
else
throw ex;
}
catch (Exception ex)
{
// general error handling
}
--------------------------------------------------
Option 2:
try{...}
catch (Exception e)
{
if (ex.GetType() == System.Data.SqlClient.SqlException
&& ((System.Data.SqlClient.SqlException)ex).State ==
1)
{
// special error handling
}
else
{
// general error handling
}
}
I want to handling the SqlException with State == 1 in a special way,
and for all others I want to use a general way to handle. Which of the
following options is better?
-----------------------------------------------------
Option 1:
try{...}
catch (System.Data.SqlClient.SqlException ex)
{
if (ex.State == 1)
{
// special error handling
}
else
throw ex;
}
catch (Exception ex)
{
// general error handling
}
--------------------------------------------------
Option 2:
try{...}
catch (Exception e)
{
if (ex.GetType() == System.Data.SqlClient.SqlException
&& ((System.Data.SqlClient.SqlException)ex).State ==
1)
{
// special error handling
}
else
{
// general error handling
}
}