Share via


Add a Class for Error Messages

In this section, you create a class named MessageConstants containing five string constants:

  • SUCCESS

  • FAILURE

  • NOT_ALLOWED

  • FORMAT_NOT_SUPPORTED

  • NO_MATCHES_FOUND

    Note

    This procedure is required by only some tutorials and report binding scenarios. This procedure is done only after the completion of Project Setup. To verify whether you need to complete this procedure, consult the table in Additional Setup Requirements.

Why build a MessageConstants Class?

In .NET projects, you use try/catch blocks to trap successes and failures when you call the underlying business logic. After the method call is made, a success or failure message is assigned (in general, to a Label control) to display the result. The success message is assigned in the try block, and the failure message is assigned in the catch block. These success and failure messages should be created as string constants, in a class that is devoted to messages.

Other constants that you create in this procedure are used when an attempted activity is not allowed, a format cannot be found, and no matches are found for a submitted value.

Note

If the general information that is provided by the constant is not enough, you can append an additional message (for example, the Message property of Exception) after the constant.

In this section: