community postAL Developmentcommunity - not Microsoftreviewed - checked by Opus

Dynamics 365 Business Central: GetLastErrorCode, GetLastErrorText and GetLastErrorCallStack Methods

The post explains three system methods for retrieving error information in Business Central AL code: GetLastErrorCode identifies error classification, GetLastErrorText provides error details, and GetLastErrorCallStack returns the call stack where the error occurred. It helps developers implement error handling and conditional logic based on error details.

post Dynamics 365 Lab

Yun Zhu · 2026-09-03 · 334 words · about 2 min

"For some errors, such as divide by zero errors and overflow errors, GetLastErrorCallStack does not return every call in the stack."

Key points

  • GetLastErrorCode retrieves the error classification and is not translated to local language
  • GetLastErrorText gets detailed error message and is translated to local language
  • GetLastErrorCallStack returns the call stack from where the error occurred, though some error types don’t return complete stacks
  • These methods work with try functions to add conditional checks for error handling

Quotes

  • “For some errors, such as divide by zero errors and overflow errors, GetLastErrorCallStack does not return every call in the stack.” (Developers need to know the limitations of call stack retrieval for certain error types and when to use the debugger instead.)

AL objects mentioned

As named in the post. A name that matches one object page by exact type and name links to it; the others stay as named.

  • other “System.GetLastErrorCode()”
  • other “System.GetLastErrorText()”
  • other “System.GetLastErrorCallStack()”
  • other “System.GetLastErrorObject()”

Heads up

  • gotcha: “For some errors, such as divide by zero errors and overflow errors, GetLastErrorCallStack does not return every call in the stack.”

Context

  • Features: error retrieval, call stack inspection, exception handling, try methods, error classification
  • Versions: Business Central 2025 wave 1 (BC26)

Source: Dynamics 365 Lab - Yun Zhu, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.