AX / 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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s