Displays an error message and ends the execution of C/AL code.
ERROR(String [, Value1, …])
- Type: Text constant or codeThis string contains the text of the error message you want to display to the user. Use percent signs (%) or number signs (#) to insert variable values into the string. Place the percent or number signs where you want to substitute the variable value. The string can be a text constant that is enabled for multilanguage functionality. For more information, see Multilanguage Development.
- Value1, …
- Type: AnyAny variable or expression to be inserted in String. You can insert up to 10 values.For '#'-type fields, the value is truncated according to the total number of number-sign characters in String. For '%'-type fields, the full length of the value is printed.
The window is automatically sized to hold the longest line of text and total number of lines.
We recommend the following guidelines for error messages:
- Describe what is wrong and how to solve the
- Write a short descriptive message. Do not use
more words than necessary.
- Always end the error message with a
- Use a text constant for the text of the
For more information, see Progress Windows, MESSAGE, ERROR, and CONFIRM Functions.
This example shows how to use the ERROR function. The code example requires that you create the following variables and text constants in the C/AL Globals window.
Finance Account #1#### must not be blocked.
AccountNo := 1230; // The execution stops when the error statement is executed // and all following statements will never be executed. ERROR(Text000, AccountNo); MESSAGE(Text001); // This line is not executed.
The error window displays the following:
Finance Account 1230 must not be blocked.
The ERROR function causes execution of C/AL code to stop. The MESSAGE function is never executed.