Training
Module
Handle errors by using application language in Dynamics 365 Business Central - Training
Learn how to handle errors in Dynamics 365 Business Central by using application language (AL).
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
When many system functions fail, they set the last-error code. If your application needs more details about an error, it can retrieve the last-error code using the GetLastError function and get a description of the error using the FormatMessage function.
The following example includes an error-handling function that prints the error message and terminates the process.
#include <windows.h>
void ErrorExit()
{
// Retrieve the system error message for the last-error code
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
if (FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL) == 0) {
MessageBox(NULL, TEXT("FormatMessage failed"), TEXT("Error"), MB_OK);
ExitProcess(dw);
}
MessageBox(NULL, (LPCTSTR)lpMsgBuf, TEXT("Error"), MB_OK);
LocalFree(lpMsgBuf);
ExitProcess(dw);
}
void main()
{
// Generate an error
if (!GetProcessId(NULL))
ErrorExit();
}
Training
Module
Handle errors by using application language in Dynamics 365 Business Central - Training
Learn how to handle errors in Dynamics 365 Business Central by using application language (AL).