{"title":"System.GetLastErrorCallStack() Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/system/system-getlasterrorcallstack-method/","by":"JOP-AL","license":"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/methods-auto/system/system-getlasterrorcallstack-method, 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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-getlasterrorcallstack-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Gets the call stack from where the last error occurred.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":116,"chars":204},{"level":2,"title":"Return Value","slug":"return-value","at":320,"chars":52},{"level":2,"title":"Remarks","slug":"remarks","at":372,"chars":369},{"level":2,"title":"Example","slug":"example","at":741,"chars":619},{"level":2,"title":"Related information","slug":"related-information","at":1360,"chars":134}],"text":"> Version: _Available or changed with runtime version 1.0._\nGets the call stack from where the last error occurred.\n## Syntax\n```al\nString :=   System.GetLastErrorCallStack()\n```\n> NOTE\n> This method can be invoked using property access syntax.\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Return Value\nString\nType: ../text/text-data-type\n## Remarks\nFor some errors, such as divide by zero errors and overflow errors, GetLastErrorCallStack does not return every call in the stack. To get the complete call stack for these types of errors, use the debugger and specify that you want to break on errors. On the Debugger page, in the Call Stack FactBox, you can view all the method calls that led to the error.\n## Example\nIn this example, an error occurs in codeunit 50003. The text of the Message includes a call to the GetLastErrorCallStack method.\n```al\n// Codeunit 50001, TestErrors1\n// OnRun trigger\nError('Some error message')\n\n// Codeunit 50002, TestErrors2\n// OnRun trigger\nClearLastError;\nif not Codeunit.Run(50001) then\n  Message('The call stack for the last error is:\\' + GetLastErrorCallStack);\n\n```\nWhen you run codeunit 50002, the message window displays the following:\nThe call stack for the last error is:\nTestErrors1\\(CodeUnit 50001\\).OnRun\\(Trigger\\) line 1\nTestErrors2\\(CodeUnit 50002\\).OnRun\\(Trigger\\) line 2\n## Related information\nsystem-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}