web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Exception handling (Try / Catch ) blocks use in Dynamics 365 finance and operations

Jayaprakash Reddy Profile Picture Jayaprakash Reddy 270

Use the throw,  try... catch,  finally,   and retry  to generate  and handle exceptions.

In transaction developments(ttsbegin/ttscommit),use the  exception  presented below:  

  • Deadlock -  Handling for deadlocks in the  database. The deadlock occurs  when multiple transactions are waiting for each other.
  • UpdateConflict -  Handling for UpdateSConflicts. The update conflict occurs  when a transaction is using OCC (Optimistic Concurrence Control). The transaction can be repeated.
  • DuplicateKeyException -  Handling for duplicate key field conflicts. Duplicity occurs when a transaction is using Optimistic Concurrence Control (OCC). The transaction can be repeated.
    #OCCRetryCount
    
        try
    
        {
    
    ttsbegin;
    
            Your code here
    
            ttscommit;
    
        }
    
        catch (Exception: :D eadlock)
    
        {
    
            Retry on deadlock
    
            retry;
    
        }
    
        catch (Exception::UpdateConflict)
    
        {
    
            Retry to resolve conflict update
    
    if (appl.ttsLevel() ==  0)
    
            {
    
                if (xSession::currentRetryCount() >= #RetryNum)
    
                {
    
                    throw Exception::UpdateConflictNotRecovered;
    
                }
    
                else
    
                {
    
                    retry;
    
                }
    
            }
    
            else
    
            {
    
                throw Exception::UpdateConflict;
    
            }
    
        }
    
        catch(Exception: :D uplicateKeyException)
    
        {
    
            Retry in case of a duplicate key conflict
    
    if (appl.ttsLevel() ==  0)
    
            {
    
                if (xSession::currentRetryCount() >= #RetryNum)
    
                {
    
                    throw Exception::D uplicateKeyExceptionNotRecovered;
    
                }
    
                else
    
                {
    
                    retry;
    
                }
    
            }
    
            else
    
            {
    
                throw Exception::D uplicateKeyException;
    
            }
    
        }

Hope you find this useful, I will come up with another interesting blog post.

Comments

*This post is locked for comments