Just been working with some code and saw this little gem.
try
{Some code}
except
showmessage('error');
end;
This is a good example of the developer being lazy and not being bothered to do something better. Can you imagine the user ringing up support and saying they are getting a 'error' message, it's not even with a capital 'E'.
There are a couple of issues I have with this bit of code. Firstly I have a rule that showmessage() is used while developing and should be removed when a deployment build is done, if a message needs to be displayed it should be in an message dialog (MessageDlg). The reason for this is that a message dialog looks better with icons specify what the message is, I use GExperts to create the code. Also, when developing I can quickly search for 'showmessage' and can see what messages need to be removed, this means there are no embarrassing debug messages displayed to the user.
Secondly is the message just says error, which it not helpful to the user or the developer when it is reported. The developer could have done something better by giving a more useful message like 'An error has occurred while...', with what the operation is doing. The developer could have also included the exception message like the following.
try
{Some code}
except
on e: exception do
MessageDlg('An error has occured in...' + e.Message, mtError, [mbOK], 0);
end;
No comments:
Post a Comment