Showing posts with label xSession::currentRetryCount(). Show all posts
Showing posts with label xSession::currentRetryCount(). Show all posts

Monday 17 November 2014

Try Throw and Exception in Axapta

Use of Try when program catch the error

Use of Throw to show our own exceptions

Exception throw within try block


see below example describe use of try,throw and exception on deadlock

     public void delete()
     {
         #OCCRetryCount
         try
         {
             ttsbegin;
             if (this.isApproved() && RouteParameters::find().BlockEditing)
                 throw error("@SYS95153");
             super();
             this.updateCheckFlag();
             ttscommit;
         }
         catch(Exception::Deadlock)
         {
               retry;
         }
         catch (Exception::UpdateConflict)
         {
             if (appl.ttsLevel() == 0)
             {
                 if (xSession::currentRetryCount() >= #RetryNum)
                 {
                         throw Exception::UpdateConflictNotRecovered;
                 }
                   else
                 {
                     retry;
                 }
             }
             else
             {
                  throw Exception::UpdateConflict;
             }
         }
     }