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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 30.04.2020, 12:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
goshoom: Exception handling in PU31
Источник: http://dev.goshoom.net/en/2020/04/ex...dling-in-pu31/
==============

In 2018, I wrote the blog post Throwing managed exceptions from X++ in D365FO, where I pondered upon how throwing proper exceptions objects in X++ would be beneficial. This is still true. I also showed a proof of concept how it can be done despite the fact that X++ doesn’t directly support it. But this has changed! Platform Update 31 has introduced the possibility to throw managed (CLR) exceptions directly with the throw statement.

Therefore you can now do things like this right from X++:

throw new System.ArgumentException('A value must be set', 'FromDate');






Then you can react to this particular type of exception and you’ll also get a lot of context, such as which argument is wrong. For example:

System.ArgumentException argEx; try{ ...}catch (argEx){ warning(strFmt("Please provide a valid value for the parameter '%1'.", argEx.ParamName));}






If you want to define your own exception class (e.g. FieldEmptyException from my previous blog post), you still can’t do it in X++ – you need a C# project or something. And it’s probably not going to change. But it shouldn’t be a big problem, because working with C# projects in D365FO is very easy.

PU31 added one more ability of throw. Imagine that you want to log an exception, but you don’t want to handle it. You catch it, log it and then you can throw another exception. But this new exception won’t have the same properties as the original one, e.g. its stack trace will show that it was thrown from your catch clause. To rethrow the same exception, use throw without any argument. Like this:

catch (ex){ logger.log(ex); throw;}








Источник: http://dev.goshoom.net/en/2020/04/ex...dling-in-pu31/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
goshoom: Catching exceptions in AX 7 Blog bot DAX Blogs 4 22.06.2017 12:49
goshoom: Exception handling with X++ and .NET Interop Blog bot DAX Blogs 0 02.09.2013 11:12
daxmusings: Exception Handling in Dynamics AX Blog bot DAX Blogs 0 16.04.2013 15:11
Issues concerning X++: Exception handling and transactions Blog bot DAX Blogs 1 14.02.2009 00:46
axaptapedia: Exception handling Blog bot DAX Blogs 0 24.06.2008 18:05

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

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

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