Rule Intro
Meaningless Catch blocks should never be used because if there is an error in the application a warning cannot be displayed to the user such as "connection failed".
Page Content
-
// C#
try
{
cnn.Open();
cmd.ExecuteReader();
}
catch
{ }
finally
{
cnn.Close();
}
- Bad code - Meaningless Catch block
-
// C#
try
{
cnn.Open();
cmd.ExecuteReader();
}
catch (SQLException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cnn.Close();
}
- Good code - Meaningful Catch block