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, ...
Unanswered

What is OCCRetryCount macro doing?

(0) ShareShare
ReportReport
Posted on by 552

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,

I have the same question (0)
  • GirishS Profile Picture
    27,825 Moderator 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.

  • Mohit Rampal Profile Picture
    12,563 Moderator on at
    RE: What is OCCRetryCount macro doing?

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

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

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

  • GirishS Profile Picture
    27,825 Moderator 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.

  • Mohit Rampal Profile Picture
    12,563 Moderator 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.

  • Ken Manhattan Profile Picture
    552 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.

  • GirishS Profile Picture
    27,825 Moderator 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.

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 582 Most Valuable Professional

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 542

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans