Do you have meaningless Catch blocks in your applications?
v3.0
Posted at
20/10/2010 7:56 PM by
system
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
Do you like this rule?
Do you follow this rule?