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

Announcements

No record found.

News and Announcements icon
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
    239,029 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans