D365FO – Generate an exception with an error message in X++

 

To generate an exception in X++ code and give a feedback to the user with an error message just use throw Error(‘Your error message’)

Here is an example

boolean isOk = false;

if (!isOK)
{
     throw Error('Operation canceled');
}

The code will stop after the exception and a red message will be shown to the user

Comments