LC0048 - StefanMaron/BusinessCentral.LinterCop GitHub Wiki
ErrorInfo
or Label
variable to improve telemetry details.
Use Error with a When Analyzing Telemetry with the Dynamics 365 Business Central Usage Analytics report, having access to the correct error message is essential for a effective analysis.
ErrorInfo
Passing an ErrorInfo
object to the Error method will improve the details of the RT0030 signal to include the error message which was shown to the user.
procedure ErrorWithErrorInfo()
var
MyErrorInfo: ErrorInfo;
begin
if not TryDoSomething() then begin
MyErrorInfo := ErrorInfo.Create(GetLastErrorText());
Error(MyErrorInfo);
end;
end;
field(3; "Dimension Code"; Code[20])
{
Caption = 'Dimension Code';
TableRelation = Dimension.Code;
trigger OnValidate()
begin
if not DimMgt.CheckDim("Dimension Code") then
Error(ErrorInfo.Create(DimMgt.GetDimErr()));
"Dimension Value Code" := '';
end;
}
External references
The examples provided below primarily focus on the details in telemetry, showing only a fraction of what the ErrorInfo
object can do. For a more comprehensive understanding and inspiration on leveraging the capabilities of the ErrorInfo object some external references below.
- ErrorInfo Data Type - Business Central | Microsoft Learn
- ErrorInfo data type & Collectible Errors | MSDyn365 Business Central - Tom Kapitan (kepty.cz)
- 3 Ways To Handle Errors In Business Central - Business Central Geek
- Dynamics 365 Business Central: changing the way of throwing Errors – Stefano Demiliani
Label
When declaring the variable as a Label Data Type
and passing this to the Error method, the details of the Error Message will be available in the telemetry. Note that placeholders, like %1, will not be populated due to the absence of the possibility to set a DataClassification on the Error Method.
procedure ErrorMessageAvailableInTelemetry()
var
UnexpectedErr: Label 'Something went wrong...';
begin
Error(UnexpectedErr);
end;
procedure ErrorMessageAvailableInTelemetry()
var
Customer: Record Customer;
UnexpectedErr: Label '%1 is not an valid Customer.';
begin
Error(UnexpectedErr, Customer.Name);
end;
procedure NoErrorMessageInTelemetry()
begin
Error('Something went wrong...'); // Use Error with a ErrorInfo or Label variable to improve telemetry details.
end;
procedure NoErrorMessageInTelemetry()
var
UnexpectedErr: Text;
begin
UnexpectedErr := 'Something went wrong...';
Error(UnexpectedErr); // Use Error with a ErrorInfo or Label variable to improve telemetry details.
end;
procedure NoErrorMessageInTelemetry()
var
Customer: Record Customer;
UnexpectedErr: Label '%1 is not an valid Customer.';
begin
Error(StrSubstNo(UnexpectedErr, Customer.Name)); // Use Error with a ErrorInfo or Label variable to improve telemetry details.
end;