Monday, August 19, 2019

Save all infoLog messages to log

private void build()
{
     #OCCRetryCount

    try
     {
         ttsBegin;
         this.buildPositionCreate();
         this.buildPositionCreateAddDetails();
         this.buildWorkerHire();
         this.buildWorkerAcctsCreate();
         this.buildWorkerPositionsCreate();
         this.buildPersonInfo();
         this.buildWorkerContactInfo();
         this.buildEmploymentDetail();
         this.buildEmploymentTerm();
         this.buildPersonCertificate();

        this.checkIfAnyError();

        if (!isValid)
             throw Exception::Error;

        ttsCommit;
     }
     catch (Exception::Deadlock)
     {
         retry;
     }
     catch (Exception::UpdateConflict)
     {
         if (appl.ttsLevel() == 0)
         {
             if (xSession::currentRetryCount() >= #RetryNum)
             {
                 this.error(strFmt('%1', Exception::UpdateConflictNotRecovered), 'PU3WLI2QKQ');
                 this.saveInfoLog(funcName());
                 throw Exception::UpdateConflictNotRecovered;
             }
             else
             {
                 retry;
             }
         }
         else
         {
             this.error(strFmt('%1', Exception::UpdateConflict), 'H2MD3D76OL');
             this.saveInfoLog(funcName());
             throw Exception::UpdateConflict;
         }
     }
     catch(Exception::DuplicateKeyException)
     {
         // retry in case of an duplicate key conflict
         if (appl.ttsLevel() == 0)
         {
             if (xSession::currentRetryCount() >= #RetryNum)
             {
                 this.error(strFmt('%1', Exception::DuplicateKeyExceptionNotRecovered), 'WU694VMXEK');
                 this.saveInfoLog(funcName());
                 throw Exception::DuplicateKeyExceptionNotRecovered;
             }
             else
             {
                 retry;
             }
         }
         else
         {
             this.error(strFmt('%1', Exception::DuplicateKeyException), '12B8CPJD4N');
             this.saveInfoLog(funcName());
             throw Exception::DuplicateKeyException;
         }
     }
     catch (Exception::Error)
     {
         this.error(this.getErrorsAsText(), 'JUXVZLON1R');
         this.saveInfoLog(funcName());
         throw Exception::Error;
     }
     catch
     {
         //always create a catch all: https://docs.microsoft.com/en-us/dynamicsax-2012/developer/exception-handling-with-try-and-catch-keywords#aa893385collapse_allen-usax60gifthe-try-and-catch-statements
         this.error(this.getErrorsAsText(), 'ORNBQPWKZ0');
         this.saveInfoLog(funcName());
         throw Exception::Error;
     }
}

No comments:

Post a Comment