Error function
Syntax
Error str
Description
Use the Error function in FieldEdit or SaveEdit PeopleCode to stop processing and display an error message. It is distinct from Warning, which displays a warning message, but does not stop processing. Error is also used in RowDelete and RowSelect PeopleCode events.
WARNING:
The behavior of the Error function in the RowSelect event is very different from its normal behavior.
See the Error in RowSelect section for more details.
The text of the error message (the str parameter), should always be stored in the Message Catalog and retrieved using the MsgGet or MsgGetText functions. This makes it much easier for the text to be translated, and it also enables you to include more detailed Explain text about the error.
Note:
If you pass a string to the Error function instead of using a Message Catalog function, the explanation text from the last call to the Message Catalog may be appended to the message. This can cause unexpected results.
See WinMessage function.
When Error executes in a PeopleCode program, the program terminates immediately and no statements after the Error are executed. In other respects behavior of Error differs, depending on which PeopleCode event the function occurs in.
Parameters
| Parameter | Description |
|---|---|
|
Str |
A string containing the text of the error message. This string should always be stored in the Message Catalog and retrieved using the MsgGet or MsgGetText function. This makes translation much easier and also enables you to provide detailed Explain text about the error. |
Returns
None.
Example
The following example, from SaveEdit PeopleCode, displays an error message, stops all save processing, and places the cursor in the QTY_ADJUSTED field. Note that SetCursorPos must be called before Error.
If PAGES2_INV_WRK.PHYS_CYC_INV_FLG = "Y" Then
SetCursorPos(%Page, PHYSICAL_INV.INV_LOT_ID, CurrentRowNumber(1), QTY_⇒
ADJUSTED, CurrentRowNumber());
Error MsgGet(11100, 180, "Message not found.");
End-If;
Errors in FieldEdit and SaveEdit
The primary use of Error is in FieldEdit and SaveEdit PeopleCode:
-
In FieldEdit, Error stops processing, displays a message, and highlights the relevant field.
-
In SaveEdit, Error stops all save processing and displays a message, but does not highlight any field. You can move the cursor to a specific field using the SetCursorPos function, but be sure to call SetCursorPos before calling Error, otherwise Error stops processing before SetCursorPos is called. Note that an Error on any field in SaveEdit stops all save processing, and no page data is saved to the database.
Errors in RowDelete
When the user attempts to delete a row of data, the system first prompts for confirmation. If the user confirms, the RowDelete event fires. An Error in the RowDelete event displays a message and prevents the row from being deleted.
Error in RowSelect
The behavior of Error in RowSelect is totally anomalous, and is supported only for backward compatibility. It is used to filter rows that are being added to a page scroll after the rows have been selected and brought into the component buffer. No message is displayed. Error causes the Component Processor to add the current row (the one where the PeopleCode is executing) to the page scroll, then stops adding any additional rows to the page scroll.
The behavior of Error in the RowSelect event enables you to filter out rows that are above or below some limiting value. In practice this technique is rarely used, because it is more efficient to filter out rows of data before they are brought into the component buffer. This can be accomplished with search views or effective date processing.
Error in PreScrollRowSelect
Error displays a message and prevents the row from being selected.
Error in ScrollRowSelect
Error displays a message, but does not prevent the row from being selected.
Errors in Other Events
Do not use the Error function in any of the remaining events, which include:
-
FieldDefault
-
FieldFormula
-
RowInit
-
FieldChange
-
Prepopup
-
RowInsert
-
SavePreChange
-
SavePostChange