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