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 think you cannot put the try catch block inside the macros - Macros is used for defining the constant values.
Thanks,
Girish S.
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.
#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.
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.
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,
Hi Ken, You can check this article on error handling.
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.
André Arnaud de Cal...
291,979
Super User 2025 Season 1
Martin Dráb
230,848
Most Valuable Professional
nmaenpaa
101,156