Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

What is OCCRetryCount macro doing?

(0) ShareShare
ReportReport
Posted on by 516

Hi,

I'm exploring some of existing classes that use / extend Runbasebatch, and I found some of it declare this macro : #OCCRetryCount

If I take look inside of this macro is like this : 

#define.RetryNum    (5)     //number of retries in catch(Exception::UpdateConflict) loop
    
#localmacro.StandardRetryCatchBlock
catch (Exception::UpdateConflict)
{
    if (appl.ttsLevel() == 0)
    {
        if (xSession::currentRetryCount() >= #RetryNum)
        {
            throw Exception::UpdateConflictNotRecovered;
        }
        else
        {
            retry;
        }
    }
    else
    {
        throw Exception::UpdateConflict;
    }
}
catch(Exception::DuplicateKeyException)
{
    if (appl.ttsLevel() == 0)
    {
        if (xSession::currentRetryCount() >= #RetryNum)
        {
            throw Exception::DuplicateKeyExceptionNotRecovered;
        }
        else
        {
            retry;
        }
    }
    else
    {
        throw Exception::DuplicateKeyException;
    }
}
#endmacro

Does it mean if I'm using this macro and in my class I'm create a Try{}..Catch{}.. I'm actually no need to add Catch{} since it is already stated in the macro ?

and if I still add my Catch{} with the same, for example I'm adding catch(Exception::Updateconflict), which one will be executed/applied, is it both ? 

Thanks,

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: What is OCCRetryCount macro doing?

    I think you cannot put the try catch block inside the macros - Macros is used for defining the constant values.

    Thanks,

    Girish S.

  • Ken Manhattan Profile Picture
    Ken Manhattan 516 on at
    RE: What is OCCRetryCount macro doing?

    Hi,

    I'm sorry, but if we declare this macro in our class, for example :

    class Testing
    {
       
        #OCCRetryCount
        
        .
        .
        .
    }

    Does it mean all the code inside the macro will be included in our class as well ?

    and since the macro contain this lines : 

    #define.RetryNum    (5)     //number of retries in catch(Exception::UpdateConflict) loop
        
    #localmacro.StandardRetryCatchBlock
    catch (Exception::UpdateConflict)
    {
        if (appl.ttsLevel() == 0)
        {
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::UpdateConflictNotRecovered;
            }
            else
            {
                retry;
            }
        }
        else
        {
            throw Exception::UpdateConflict;
        }
    }
    catch(Exception::DuplicateKeyException)
    {
        if (appl.ttsLevel() == 0)
        {
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::DuplicateKeyExceptionNotRecovered;
            }
            else
            {
                retry;
            }
        }
        else
        {
            throw Exception::DuplicateKeyException;
        }
    }
    #endmacro

    Not only they recognize the number of Retry which is 5, but also wherever I put Try keyword, there will Catch() with the same instruction as inside the macro ?

    Sorry, a bit confuse on how is the proper usage of Macro.

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: What is OCCRetryCount macro doing?

    #RetryNum and Retry are different. You can name anything in macro instead of #RetryNum. This macro in code is used to set number of times, code will be retried. Retry keyword will call Try statement again.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: What is OCCRetryCount macro doing?

    In the macro you are defining the constant value for retry count - How many times retry should happen.

    So, adding catch statement has nothing to do with macro.

    Thanks,

    Girish S.

  • Ken Manhattan Profile Picture
    Ken Manhattan 516 on at
    RE: What is OCCRetryCount macro doing?

    Hi both,

    yes, however my doubts is, if we already declared/defined this Macro in our class, does it mean we do not need to add (type) again those Catch() ?

    or if add again our own Catch(), will it be duplicate, replaced the one in Macro, or which one took precedence ?

    Thanks,

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: What is OCCRetryCount macro doing?

    Hi Ken, You can check this article on error handling.

    community.dynamics.com/.../x-the-catch

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: What is OCCRetryCount macro doing?

    Hi ken,

    Retry count will retrying the same process again and again until the retry count mentioned in the macros exceeds the limit.

    Refer to the below blog.

    https://rahulmsdax.blogspot.com/2018/12/try-catch-in-ax-2012-dynamics-365_20.html

    Thanks,

    Girish S.

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans