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)

Error handling in AIF service.

(0) ShareShare
ReportReport
Posted on by

Hi, 

I'm trying to do an exception handling in my code for a custom service which creates PO in AX.

But seems I've no control in handling it by try catch block. 

Here is my scenario, I have PO with 5 lines to be created, and even if my 3rd line thrown error on creation, I should be able to skip the line, log the message and create the rest of the lines.

while(purchLinesEnum.moveNext())//List enumerator
{
    //Contract class which holds the details for PO lines
    contractImp = purchLinesEnum.current(); 
    try
    {
        //A method which creates PO line, by using PurchLine.createLine method
        this.createPurchLine(purchTable,contractImp,inventLocation);
    }
    catch
    {
        ret = false; //A Boolean variable which should be set to false on error. 
    }
}

Note: I have no transaction pair written outer the try catch block.

For this code, I have an exception returned to caller as below,

Eception-not-handled.png

I try to debug the code, which resulted as below,

Code-Block.png

EXC.png

Could anyone help me to understand whats happening here. 

Thanks in Advance,

Abida

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    It's been discussed here quite a few times. The service operation is executed inside a transaction and you can't catch (normal) exceptions inside transactions, because AX skips the rest of the transaction and continues processing after the topmost transaction block.

    If you insist, look at Error handling in methods exposed as AIF service thread for a workaround.

  • Community Member Profile Picture
    on at

    Hi Martin,

    Sorry I was unaware of this posts.

    Thank you for you help and quick response. This will help me to do a workaround.

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans