# AL error handling
> NOTE
> We're working to improve the onboarding experience for AL developers. If you have feedback about this article, use the Feedback section at the bottom of the article to tell us what you'd like to see.
> We also welcome contributions to our documentation. Learn more about contributing in Contribute to the help<../help/contributor-guide#contributing>.
The AL language has many error handling features, which can help you deal with unexpected situations that occur when code is run. This section contains articles about using these methods in AL to handle errors that occur during code execution, while making sure that your application has a consistent user interface.
The following articles discuss the different aspects of error handling in AL:
 Failure modeling and robust coding practices<devenv-robust-coding-practices>
 Understanding the error dialog<devenv-error-dialog>
 User experience guidelines for errors<devenv-error-handling-guidelines>
 devenv-actionable-errors
 Collecting errors<devenv-error-collection>
 devenv-handling-errors-using-try-methods
 Understanding the error dialog<devenv-error-dialog>
## Error handling methods in AL
For examples of using different error handling methods in AL, see the following table:
Method|Description
methods-auto/system/system-clearlasterror-method|Removes the last error message from memory.
methods-auto/dialog/dialog-data-type|Represents a dialog window.
methods-auto/dialog/dialog-error-errorinfo-method|Displays an error message and ends the execution of AL code.
methods-auto/errorinfo/errorinfo-data-type|Contains a set of methods that helps identify errors, classify these errors, send errors to telemetry and display UI messages. Go to the data type article for an overview.
methods-auto/system/system-data-type|Is a complex data type and contains multiple methods for getting and classifying errors.
methods-auto/system/system-getlasterrorcallstack-method|Gets the call stack from where the last error occurred.
methods-auto/system/system-getlasterrorcode-method|Gets the classification of the last error that occurred.
methods-auto/system/system-getlasterrorobject-method|Gets the last System.Exception object that occurred.
methods-auto/system/system-getlasterrortext--method|Gets the last error that occurred in the debugger.
> TIP
> If you already know the name of a data type, use the Filter by title field in the upper left corner, above the table of contents to find the topic faster.
## Error handling strategies
For examples of different error handling strategies, see the following table:
If you want to...|Then use
Run a codeunit and decide to do something if an error occurs.|`if not Codeunit.run()`. See Codeunit.Run return value<methods-auto/codeunit/codeunit-run-method>
Check for an error and show an error dialog to the user.|`Dialog.Error(Message: ErrorInfo)`. See methods-auto/dialog/dialog-error-errorinfo-method.
Check for an error and show an error dialog to the user with added support information.|Using the ErrorInfo Data Type with the Error Method<methods-auto/errorinfo/errorinfo-data-type>
Do bulk validations in AL and not show an error dialog for each of them to the user.|Collecting Errors<devenv-error-collection>
Catch errors raised by other AL methods|devenv-handling-errors-using-try-methods
Catch errors/exceptions that are thrown during .NET framework interoperability operations (on-premises only).|Handling .NET Exceptions using Try Methods<devenv-handling-errors-using-try-methods>
Handle errors happening in Page Background Tasks|The OnPageBackgroundTaskError trigger of the page. See devenv-page-background-tasks#handling-errors.
Log an error that happens within a database transaction (that rollback)|Either log the error in a new session using a background session, or log the error to telemetry (see methods-auto/session/session-logmessage-string-string-verbosity-dataclassification-telemetryscope-dictionary[text,text]-method or ../administration/telemetry-feature-telemetry#LogError ).
## Guidelines for error messages
Improving error handling and error messages reduces friction for the users and highly impacts the user experience. Clear, informative error messages help users understand what went wrong and how to correct it, reducing frustration, and improving user satisfaction.
For guidance on how to formulate good error messages, see Error message best practices - what to say?<devenv-error-handling-guidelines#error_message_best_practices>.
## Error telemetry (emitted by the AL runtime)
When a user gets an error dialog while working in Business Central, a telemetry signal is emitted, which can be logged in an Azure Application Insights resource. This telemetry data let's you identify and analyze where and why the error occurs. You can also set up alerts in Azure Application Insights to get notified if many users experience errors.
There are three types of telemetry data emitted about errors
 Error message quality
 Error dialogs shown to users
 Permission errors
If you want to...|Then look at this telemetry
Understand if users understand the error messages they see.|Error message quality telemetry<../administration/telemetry-error-message-voting-trace>
Understand which error dialogs users see and where in the AL code the error is raised.|../administration/telemetry-error-method-trace
Understand when users get error dialogs about lack of permissions.|../administration/telemetry-permission-error-trace
## Error telemetry (emit your own)
You can emit your own telemetry about error situations by using the Telemetry AL module. Using this module, you can simplify the way you monitor the health of your app and also monitor the uptake and usage of application features.
See ../administration/telemetry-feature-telemetry#LogError.
## Related information
Failure modeling and robust coding practices<devenv-robust-coding-practices>
Understanding the error dialog<devenv-error-dialog>
User experience guidelines for errors<devenv-error-handling-guidelines>
devenv-actionable-errors
Collecting errors<devenv-error-collection>
devenv-handling-errors-using-try-methods
devenv-page-background-tasks#handling-errors
../administration/telemetry-feature-telemetry#LogError
Error message quality telemetry<../administration/telemetry-error-message-voting-trace>
../administration/telemetry-error-method-trace
../administration/telemetry-permission-error-trace
devenv-al-control-statements
AL development environment<devenv-reference-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-al-error-handling, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-al-error-handling/
