General X++ Development

How do I get the exception message in X++?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

How do I get the exception message in X++?

SSunny Vasty75 reputation · answered Aug 13, 2026

For normal X++ errors, the useful message is often already in the Infolog.

For CLR exceptions:

X++
catch (Exception::CLRError)
{
    System.Exception ex = CLRInterop::getLastException();

    error(ex ? ex.get_Message() : 'CLR error.');
}

Do not replace a useful exception with something like "An error occurred." If you are handling the exception, keep enough detail to actually troubleshoot it.