Sometimes we see catch statement does not catch the errors even though the code looks good.
The below code looks good for me. But, still not showing my custom exceptions.
Reason:
Because the try and catch statement is inside the transaction(ttsbegin and ttscommit) and this is what causing the issue.
Solution:
ttsbegin and ttscommit should be always inside the try and catch statements as shown below.
The below code looks good for me. But, still not showing my custom exceptions.
while (resultSet.next())
{
//some logic (...)
ttsbegin;
//This is a custom table that stores to where I want to integrate the given customer
while select integrationCompany
where integrationCompany.CRMCompany == customerInfo.parmCRMDataAreaId()
{
changeCompany(integrationCompany.ERPCompany)
{
try
{
customerInfo.createCustomer();
//.. some more logic
}
catch
{
// My catch Block, that should update the source database to set
// the processing status to "error"
ttsAbort;
}
}
}
ttsCommit;
}
Reason:
Because the try and catch statement is inside the transaction(ttsbegin and ttscommit) and this is what causing the issue.
Solution:
ttsbegin and ttscommit should be always inside the try and catch statements as shown below.
while (resultSet.next())
{
//some logic (...)
//This is a custom table that stores to where I want to integrate the given customer
while select integrationCompany
where integrationCompany.CRMCompany == customerInfo.parmCRMDataAreaId()
{
changeCompany(integrationCompany.ERPCompany)
{
try
{
ttsbegin;
customerInfo.createCustomer();
//.. some more logic
ttscommit
}
catch
{
// My catch Block, that should update the source database to set
// the processing status to "error";
ttsbegin;
//you update statement here
ttscommit;
}
}
}
}
For more details please refer :
https://stackoverflow.com/questions/27529308/strange- behavior-with-try-catch-on- dynamics-ax-2012
Nice blog. You have provided such a useful informartion in this blog. Thanks for sharing.
ReplyDeleteMS Dynamics Operation Trade and Logistics Training
I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. https://catcherrors.com/repos/pandas-dev/pandas
ReplyDeleteThank you so much, I was having hard time figuring it out why my code was not able to catch exceptions
ReplyDelete