Home
Do you use resource file to store all the messages and globlal strings?
  v1.0 Posted at 27/04/2018 7:14 AM by Tiago Araujo
Storing all the messages and global strings in one place will make it easy to manage them and to keep the applications in the same style.

Code_StoreMessage.jpg
​Store messages in the Message.resx

Catch(SqlNullValueException sqlex)
{
Response.Write("The value cannot be null.");
}

Bad Example - if you want to change the message, it will cost you lots of time to investigate every try-catch block

Catch(SqlNullValueException sqlex)
{
Response.Write(GetGlobalResourceObject("Messages", "SqlValueNotNull"));
}

Better Example - better than the hard code, but still wordy

Catch(SqlNullValueException sqlex)
{
Response.Write(Resources.Messages.SqlValueNotNull); 'Good Code - storing message in resource file.

Good Example

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.