Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Catch error does not catch when the error is indirect call

(0) ShareShare
ReportReport
Posted on by 516

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,

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,962 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.
  • Layan Jwei Profile Picture
    Layan Jwei 7,679 Super User 2025 Season 1 on at
    Catch error does not catch when the error is indirect call
    Hi Ken,
     
    Is this answered or do you still need help?
  • Layan Jwei Profile Picture
    Layan Jwei 7,679 Super User 2025 Season 1 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

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 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;
    }

  • Ken Manhattan Profile Picture
    Ken Manhattan 516 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
    Ken Manhattan 516 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,

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,160 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans