Blog Listem

1 Aralık 2015 Salı

AX 2012 - Try - catch

Try/catch hakkında güzel bir uyarı yazısı var. Aşağıdaki kod oradan alıntı:

          void post(int amount)
    {
        #OCCRetryCount
        MyPostings debit;
        MyPostings credit;

        System.Exception ex;
        
        try        

        {
            ttsBegin;
            
            debit = MyPostings::find('debit'true);
            debit.Amount += amount;
            debit.update();
            
            credit = MyPostings::find('credit'true);
            credit.Amount -= amount;
            credit.update();
            
            ttsCommit;  
        }
        catch (Exception::UpdateConflict)
        {
            if (appl.ttsLevel() != 0)
            {
                throw Exception::UpdateConflict;
            }
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::UpdateConflictNotRecovered;
            }
            retry;
        }
        catch (Exception::DuplicateKeyException)
        {
            if (appl.ttsLevel() != 0)
            {
                throw Exception::DuplicateKeyException;
            }
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::DuplicateKeyExceptionNotRecovered;
            }  
            retry;
        }

        catch (Exception::Deadlock)
        {
            if (xSession::currentRetryCount() >= #RetryNum)
            {
                throw Exception::Deadlock;
            }
            retry;
        }

        catch(Exception::CLRError)
        {
          ex = ClrInterop::getLastException();
        if (ex != null)
        {
            ex = ex.get_InnerException();
            if (ex != null)
            {
                error(ex.ToString());
            }
            else
                error(AifUtil::getClrErrorMessage());
        }
        else
                error(AifUtil::getClrErrorMessage());
        }
        catch        
        {
            warning(infolog.text());
            if (appl.ttsLevel() != 0)
            {
                throw error("Something happened, that the logic was not designed to handle – please log a bug.");
            }
            error("Something bad happened - try again later");
        }  
    }

Hiç yorum yok:

Yorum Gönder