Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

'server' method throwing error needs to be 'caught' for more meaningful message.

Posted on by 3,061

Here is what I'm trying to do.

I am calling code which eventually leads us to Classes\DimensionDefaultingEngine\constructForMainAccountId method. This method will throw the following error correctly:

if (!_mainAccountId || !_accountStructureId)
{
throw error(Error::wrongUseOfFunction(funcName()));
}

The account structure for the main account is not setup correctly.  This is perfectly fine. The error should be thrown.

What I want to do is 'catch' this thrown error so that I can give the user a more meaningful message to have them fix the problem.

try { ...}

catch (Exception::error){

error("Meaningful message");

}

This try / catch doesn't seem to want to do anything.

*This post is locked for comments

  • b_radlyjames Profile Picture
    b_radlyjames 3,061 on at
    RE: 'server' method throwing error needs to be 'caught' for more meaningful message.

    Thanks Joris!  This was exactly it.

  • Verified answer
    Joris dG Profile Picture
    Joris dG 17,775 on at
    RE: 'server' method throwing error needs to be 'caught' for more meaningful message.

    try-catch in AX has specific behaviors based on transaction scope. The code where you placed the try catch is likely being called from within a transaction scope, which means you essentially can't catch it.

    Check this out: daxmusings.codecrib.com/.../exception-handling-in-dynamics-ax.html

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,228 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans