AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 21.12.2007, 12:30   #1  
Blog bot is offline
Blog bot
Участник
 
25,506 / 847 (80) +++++++
Регистрация: 28.10.2006
Holzheys: X++ Transactions, exceptions and updateconflicts.
Источник: http://holzhey.isa-geek.com/blog/pos...conflicts.aspx
==============

In September, I posted an article on x++ transactions unique behaviors. I am following up now with another case where they are even more unique, and where it is an exception to the transaction exception behavior.

In the event that you running under a transaction and in nested try-catch blocks the catch block nearest to a updateconflict exception that catches that exception is allowed to correct that error and continue.
Example code below:

X++:
   1:     static void RetrysWithException()
   2:      {
   3:          CustTable custTable;
   4:         int retryCount;
   5:         ;
   6:   
   7:   
   8:         ttsbegin; 
   9:   
  10:   
  11:   
  12:   
  13:         select forupdate custTable where custTable.AccountNum == 'S135' && custTable.CustGroup == '00';
  14:         retryCount = 0;
  15:   
  16:   
  17:   
  18:   
  19:         try // The ttslevel for this try-catch block is one
  20:         {
  21:                 custTable.CreditRating = strfmt("%1",str2int(custTable.CreditRating)+1);
  22:                 custTable.update(); // The UpdateConflict will be thrown inside this method. 
  23:                 info(strfmt("CreditRating = %1", custTable.CreditRating));
  24:         }
  25:         catch (Exception::UpdateConflict) 
  26:         {
  27:                 if( retryCount < 4)
  28:                 {
  29:                     retryCount ++;
  30:   
  31:   
  32:   
  33:   
  34:                     // reread the row without rolling back the transaction
  35:                     custTable.reread();
  36:                     retry;
  37:                 } else // no more than 5 retries allowed;
  38:                    // may be the business logic requires a try here
  39:                           if (appl.ttslevel() == 0)
  40:                      retry;
  41:                   else
  42:                       throw Exception::UpdateConflict;
  43:                 }
  44:             }
  45:         ttscommit; 
  46:      }
Источник: http://holzhey.isa-geek.com/blog/pos...conflicts.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 09.10.2008, 23:54   #2  
Wamr is offline
Wamr
----------------
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
 
1,737 / 858 (32) +++++++
Регистрация: 15.01.2002
Адрес: Москва
Записей в блоге: 7
Интересное замечание, что UpdateConflict можно обрабатывать ВНУТРИ транзакции, в отличии от всех других видов Exception, которые отлавливаются только за пределами первого блока ttsbegin-ttscommit
Старый 10.10.2008, 01:23   #3  
kashperuk is offline
kashperuk
Участник
Аватар для kashperuk
MCBMSS
Соотечественники
Сотрудники Microsoft Dynamics
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии 2011
Лучший по профессии 2009
 
4,361 / 2084 (78) +++++++++
Регистрация: 30.05.2004
Адрес: Atlanta, GA, USA
Цитата:
Сообщение от Wamr Посмотреть сообщение
Интересное замечание, что UpdateConflict можно обрабатывать ВНУТРИ транзакции, в отличии от всех других видов Exception, которые отлавливаются только за пределами первого блока ttsbegin-ttscommit
Думаю, нужно уточнить, что первый- не значит самый близкий от места ошибки, а именно первый (ttsLevel == 1)
 


Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 20:13.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.