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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Catch error does not catch when the error is indirect call

(0) ShareShare
ReportReport
Posted on by 552

Hi,

In my Try..Catch() block, I'm calling existing function for posting Sales Order Invoice, however when there is something happened in the invoice process, the error does not catch. For example the code is like this : 

#OCCRetryCount

While select myOpenSalesTable 
{
    ttsbegin;
    Try
    {
        SalesFormLetter         formLetterObj;
        formLetterObj   = SalesFormLetter::construct(DocumentStatus::Invoice);
        formLetterObj.update(myOpenSalesTable);
    
    }
    catch(Exception::Error)
    {
        .
        .
        retry;
    }
    catch (Exception::UpdateConflict)
    {
        .
        .
        retry;
    }
    
    ttscommit;
}

As I put my Retry inside the catch, but because it is not "trapped" inside, the process will stop "abruptly"

I have 2 questions about this:

1. How to make the FormLetter.update() process, when it is error, also trapped in my Catch()

2. Since I included #OCCRetryCount macro in my class, while the process is inside "While..." loop, should I still need compare the number of Retry and make the process continue to the next record when error happened and already exceeded the retry account ? something like this : 

catch(Exception:Error)
{
    if(xSession::CurrentRetryCount() >= #RetryNum)
        {
            error();
            continue;
        }
        else 
        {
            retry;
        }
}

Thanks,

I have the same question (0)
  • Ken Manhattan Profile Picture
    552 on at
    RE: Catch error does not catch when the error is indirect call

    Hello,

    Is there anyone can help me for some advice what to do ? especially about question no.1?

    I have searched at any existing article, blog, Microsoft docs, but all is confusing to me as it all only a standard usage with no further explanation about some specific issue like mine.

    I can inform further as well if my question or description not that clear.

    Thanks,

  • Ken Manhattan Profile Picture
    552 on at
    RE: Catch error does not catch when the error is indirect call

    Hello,

    Is there anyone can help me for some advice what to do ? especially about question no.1?

    I have searched at any existing article, blog, Microsoft docs, but all is confusing to me as it all only a standard usage with no further explanation about some specific issue like mine.

    I can inform further as well if my question or description not that clear.

    Thanks,

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at
    RE: Catch error does not catch when the error is indirect call

    Hi Ken, Can you try adding below code at Line# 2 in the first screenshot and use xppEx in catch statement

           

    Microsoft.Dynamics.Ax.Xpp.ErrorException xppEx;

    catch(xppEx)
    {
        //infolog.text(); This will give you the error message thrown by system
        retry;
    }

  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    RE: Catch error does not catch when the error is indirect call

    Hi Ken,

    Try this and you should be able to catch the error.

    System.Exception ex;
    try
    {
    
    }
    catch(ex)
    {
        error(ex.Message)
    }





    Thanks,
    Layan

  • Layan Jwei Profile Picture
    8,097 Super User 2025 Season 2 on at
    Catch error does not catch when the error is indirect call
    Hi Ken,
     
    Is this answered or do you still need help?
  • Suggested answer
    Martin Dráb Profile Picture
    237,681 Most Valuable Professional on at
    Catch error does not catch when the error is indirect call
    Ken, the reason why your code can't catch exceptions is because the try/catch blocks are inside a transaction. You can't catch exceptions there.
     
    Move ttssbegin/ttscomit to the 'try' block.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans