Dialog.Error(ErrorInfo) Method

Version: Available or changed with runtime version 3.0.

Displays an error message and ends the execution of AL code.

Note

From runtime version 8.0 and onward, this method is supported in Business Central online.

Syntax

 Dialog.Error(Message: ErrorInfo)

Note

This method can be invoked without specifying the data type name.

Parameters

Message
 Type: ErrorInfo
The ErrorInfo structure that contains error message, error type, verbosity, and data classification.

Remarks

The window is automatically sized to hold the longest line of text and total number of lines.

Note

Use this version of the Dialog.Error method compared to the older Dialog.Error(Text [, Any,...]) Method that only supports inputing a string for the error message body.

Guidelines for error messages

Improving error handling and error messages reduces friction for the users and highly impacts the user experience. Clear and informative error messages help users understand what went wrong and how to correct it, which reduces frustration, and improves user satisfaction.

For guidance on how to formulate good error messages, see Error message best practices - what to say?.

Example

This example shows how to use the Error method.

procedure InitializeFromCurrentApp()
var
    DoNotBlockErrorInfo: ErrorInfo;
    IsBlocked: Boolean;
begin
    IsBlocked := // Some logic that determines whether the account is blocked
    
    if IsBlocked then
    begin
        // Setup ErrorInfo object
        DoNotBlockErrorInfo.Message('Finance Account 1230 must not be blocked.');
        DoNotBlockErrorInfo.DetailedMessage('Some additional information that can help the person troubleshooting this issue.');
        // Add more properties for ErrorInfo depending on the scenario
        //   Maybe add a title to the error message 
        //   Maybe make the error message actionable (add fix-it or show-it actions)

        Error(DoNotBlockErrorInfo);

        // Code execution stops here
        Message('This line will never run');
    end;
end;

The error window displays the following:

Finance Account 1230 must not be blocked.

The Error method causes execution of AL code to stop. Message Method is never executed.

Error handling overview
Analyzing Error method telemetry
Dialog data type
Get started with AL
Developing extensions