The code below contains a try/catch that we use a lot when developing batch jobs, especially multi-threaded ones.
It deals with frequently occurring exceptions that, in some cases, can be easily solved by retrying/continuing:
-> Deadlocks
-> Update conflicts
-> Duplicate key conflicts
#OCCRetryCount
try
{
ttsbegin;
// do stuff here
ttsCommit;
}
catch (Exception::Deadlock)
{
// retry on deadlock
retry;
}
catch (Exception::UpdateConflict)
{
// try to resolve update conflict
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
catch(Exception::DuplicateKeyException)
{
// retry in case of an duplicate key conflict
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::DuplicateKeyExceptionNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::DuplicateKeyException;
}
}
Please note that retry keyword is retrying the same record again and again. Continue keys word is skip the present record and continue with the next record.
Example:
while (gQueryRun.next())
{
inventJournalTable = gQueryRun.get(tableNum(inventJournalTable));
if (inventJournalTable.Posted == NoYes::No)
{
JournalCheckPost journalCheckPost;
journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);
try
{
ttsbegin;
if(journalCheckPost.validate())
{
journalCheckPost.run();
}
ttscommit;
}
catch (Exception::Deadlock)
{
continue;
}
catch (Exception::Error)
{
continue;
}
catch (Exception::Warning)
{
CLRInterop::getLastException();
continue;
}
catch (Exception::CLRError)
{
CLRInterop::getLastException();
continue;
}
}
}
It deals with frequently occurring exceptions that, in some cases, can be easily solved by retrying/continuing:
-> Deadlocks
-> Update conflicts
-> Duplicate key conflicts
#OCCRetryCount
try
{
ttsbegin;
// do stuff here
ttsCommit;
}
catch (Exception::Deadlock)
{
// retry on deadlock
retry;
}
catch (Exception::UpdateConflict)
{
// try to resolve update conflict
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
catch(Exception::DuplicateKeyException)
{
// retry in case of an duplicate key conflict
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::DuplicateKeyExceptionNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::DuplicateKeyException;
}
}
Please note that retry keyword is retrying the same record again and again. Continue keys word is skip the present record and continue with the next record.
Example:
while (gQueryRun.next())
{
inventJournalTable = gQueryRun.get(tableNum(inventJournalTable));
if (inventJournalTable.Posted == NoYes::No)
{
JournalCheckPost journalCheckPost;
journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);
try
{
ttsbegin;
if(journalCheckPost.validate())
{
journalCheckPost.run();
}
ttscommit;
}
catch (Exception::Deadlock)
{
continue;
}
catch (Exception::Error)
{
continue;
}
catch (Exception::Warning)
{
CLRInterop::getLastException();
continue;
}
catch (Exception::CLRError)
{
CLRInterop::getLastException();
continue;
}
}
}
Thanks for such a great article here.
ReplyDeleteMS Dynamics AX Online Training
Thanks for picking out the time to discuss this, I feel great about it and love studying more on this topic. It is extremely helpful for me. Thanks for such a valuable help again. comment devenir rentier
ReplyDeleteFinances exist on the state level and also on the manufactures and branches' level too, and in such conditions, when the most part of the manufactures are not state. loans
ReplyDeleteI definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. view website
ReplyDeleteThanks for the blog filled with so many information. Stopping by your blog helped me to get what I was looking for. Now my task has become as easy as ABC. source
ReplyDeleteThanks for sharing information. Nice blog
ReplyDeleteD365 finance and operations
D365 finance and operations online training
This latest first appears to be a part of value of main industrial funds, later it is moved to the cost price of a ready product (that is to the value too) and after its realization, and it is set the depression fund. Dollar General
ReplyDeleteIt's important that you know what rates and fees will be applied to your merchant services account. selling credit card machines
ReplyDeleteHowever, because a merchant is dealing with sensitive financial information, it is important to have security protocols in place to prevent fraud. Merchant Account Referral Program
ReplyDeleteIn order How to be a Payment Processing Company in 2022, you must have a strong understanding of the latest payment processing technologies and be able to offer your clients a variety of payment processing options. You must also be able to provide your clients with a high level of customer service and support.
ReplyDeleteI learn some new stuff from it too, thanks for sharing your information. How to be a Payment Processor
ReplyDeleteWow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also Selling Merchant Services
ReplyDeleteI have seen the best content ever. I will suggest choosing these Best Loan Company in Jaipur
ReplyDeletePersonal Loan Agency in jaipur
HDFC Personal Loan in Jaipur
Very efficiently written information. It will be beneficial to anybody who utilizes it, including me. Keep up the good work. For sure i will check out more posts. This site seems to get a good amount of visitors. https://catcherrors.com/
ReplyDeleteI felt astoundingly happy while examining this site. This was really outstandingly illuminating site for me. I really favored it. This was genuinely a true post. Thankful!. Testogen
ReplyDelete