AL Error Handling

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 introduce error handling in AL:

Error handling methods in AL

For examples of using different error handling methods in AL, see the following table:

Method Description
ClearLastError Method Removes the last error message from memory.
Dialog Data Type Represents a dialog window.
Error Method Displays an error message and ends the execution of AL code.
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.
System Data Type Is a complex data type and contains multiple methods for getting and classifying errors.
GetLastErrorCallStack Method Gets the call stack from where the last error occurred.
GetLastErrorCode Method Gets the classification of the last error that occurred.
GetLastErrorObject Method Gets the last System.Exception object that occurred.
GetLastErrorText Method Gets the last error that occurred in the debugger.


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 code unit and decide to do something if an error occurs. if not For more information, see Codeunit.Run return value
Check for an error and show an error dialog to the user. Dialog.Error(Message: ErrorInfo). For more information, see Error 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
Do bulk validations in AL and not show an error dialog for each of them to the user. Collecting Errors
Catch errors raised by other AL methods 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
Log an error that happens within a database transaction (that rollback) Either log the error in a new session using a background session, or use Session.LogMessage to log the error to telemetry.

See also

AL Control Statements
AL Development Environment