web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
Posted on by 3,155

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

I have the same question (0)
  • Verified answer
    Joris dG Profile Picture
    17,775 on at

    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

  • b_radlyjames Profile Picture
    3,155 on at

    Thanks Joris!  This was exactly it.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#2
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

#2
Rahul.p Profile Picture

Rahul.p 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans