topic hubAL Developmentofficial - Microsoftreviewed - checked by Opus

Error handling

Error handling in AL for Business Central covers error dialogs, try methods, collectible errors, actionable errors with Fix-it and Show-it actions, failure modeling, UX guidelines, and error telemetry. It answers how to raise, catch, collect, present and log errors.

Path: Development > Programming in the AL language > Error handling · tier official · system development · narrative reviewed (checked by Opus)

Overview

This section explains how to deal with runtime errors in AL code. It starts with the general “AL error handling” page, which lists the main strategies: error dialogs, try methods, error collection, telemetry, the ErrorInfo data type and error message quality. The other pages go deeper on each strategy.

For writing errors, “Actionable errors” and “User experience guidelines for errors” describe how to use ErrorInfo with Fix-it and Show-it actions, and how to word and format messages. For catching and collecting errors, “Handling errors using try methods” and “Collecting Errors” cover the TryFunction attribute and the ErrorBehavior attribute with the error collection API. “Failure modeling and robust coding practices” gives the design principles behind defensive code.

For investigating errors, “Understanding the error dialog” explains the details users can copy, such as the AL call stack and the Application Insights session ID. The Error telemetry subtopic covers logging errors and feature usage to Application Insights. A subtopic with AL language reference pages for errors is also part of the section. Start with “AL error handling”, then pick the page that matches your task.

Key points

  • Actionable errors use ErrorInfo objects with up to two actions: Fix-it actions that apply a recommended solution and Show-it actions that navigate the user to relevant information.
  • Try methods use the TryFunction attribute, return a boolean, and let you read the error with GetLastErrorText and GetLastErrorObject. They have restrictions on database writes, and the page mentions runtime version 2.0.
  • Collectible errors let a procedure gather several validation errors instead of stopping at the first. They use the ErrorBehavior attribute and an error collection API, and you can show the errors in the standard dialog or a custom UI.
  • The error dialog has a Copy Details section with the AL call stack and the Application Insights session ID. The page mentions 2022 release wave 2 and 2023 release wave 1.
  • Failure modeling rests on six principles: do not trust external code, consumers or the environment; offer graceful degradation; hide internal data structures; and assume improbable events will happen at scale.
  • UX guidelines cover error message formatting, voice, validation errors, and best practices for error dialogs.
  • Error telemetry covers logging to Application Insights, error message votes, permission errors (RT0031), and using the Telemetry AL module to log feature usage, errors and uptake.

Subtopics

More Learn pages

Videos, posts and code changes

Linked by a Haiku matcher with a grounding quote from the item’s summary (link/topics.ts); machine-generated.

Source: Microsoft Learn (CC BY 4.0). Descriptions are Learn’s own.

What Learn documents here 8 of 16 Learn pages

Show 8 more