Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / What is the difference...
Finance forum
Answered

What is the difference between Microsoft.Dynamics.Ax.Xpp.ErrorException and System.Exception ?

Posted on by 390
Hi,
 
What actually the different between Microsoft.Dynamics.Ax.Xpp.ErrorException and System.Exception ? 
And if I run a Runnable class, which error will be catch ? and what is the reason ?
 
The main issue is in that Runnable class, and inside a Try..Catch... I'm deleting some record which at some case it is not allowed, for example / Delete purchtable/ while the PO already confirmed. I want to catch the message of the error, in standard or manual delete from the UI, I think it will says /If the previous document exist, cannot delete the record/ or something like that. What do I need to do to catch or get the error message ?
 
 
 
Thanks
 
 
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 228,135 Most Valuable Professional on at
    What is the difference between Microsoft.Dynamics.Ax.Xpp.ErrorException and System.Exception ?
    If you just want to collect infolog messages, adding them to infolog once more sounds like a bug to me. Get messages and leave the exception intact, instead of throwing new exception with the same messages. For example:
    try
    {
        ...
    }
    catch (Exception::Error)
    {
        ...
        throw;
    }
    Also note that you currently process all messages in infolog, even if there is something added before starting your process. It may be irrelevant in a custom service, but consider remembering the value of infologLine() before starting the process and take just messages from this line.
     
    I'm not sure what you mean by your remark about validateDelete().
  • Ken Manhattan Profile Picture
    Ken Manhattan 390 on at
    What is the difference between Microsoft.Dynamics.Ax.Xpp.ErrorException and System.Exception ?
    Hi Martin,
     
    The purpose is really to catch the error message from the system it self. And this code I will use it in my custom API, so when it is run, and error happened, the custom API will send the response of the same error message as what system normally given when it is happened in UI. I do not want to return my custom message.
     
    The validateDelete() it self I think I can leave it as the standard works, can I say that ? It is just when it the "action" hit error, I will have the standard error message (in my API response)
     
  • Martin Dráb Profile Picture
    Martin Dráb 228,135 Most Valuable Professional on at
    What is the difference between Microsoft.Dynamics.Ax.Xpp.ErrorException and System.Exception ?
    I don't see the point of your code. It seems to me that it merely duplicates infolog messages, because it takes what's in infolog and adds it once more as a new error message.
    What are you trying to achieve?
     
    Note that you should use validateDelete() to check whether a record can be deleted.
  • Ken Manhattan Profile Picture
    Ken Manhattan 390 on at
    What is the difference between Microsoft.Dynamics.Ax.Xpp.ErrorException and System.Exception ?
    Noted,
     
    For my case, whereby I want to catch error like when the code try to delete a confirmed PO, which in standard F&O cannot delete, is below make sense ?
     
    Try
    {
       delete_from Purchtable where .....
    }
     
    Catch (Exception::error)
    {
        
    container   infoData = infolog.infologData();
    Str1260     errorTxt;
              for (int i = 1; i <= conLen(infoData); i++)
                        {
                            container internalInfoData = conPeek(infoData, i);
                            if (errorTxt == "")
                            {
                                errorTxt =  conPeek(internalInfoData, 2);
                            }
                            else
                            {
                                errorTxt += ";" + conPeek(internalInfoData, 2);
                            }
                        }
              errorMessage = errorTxt;
              throw Error(errorMessage);
    }
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 228,135 Most Valuable Professional on at
    What is the difference between Microsoft.Dynamics.Ax.Xpp.ErrorException and System.Exception ?
    You'll need to catch the exception to be able to react to it.
     
    Catching a CLR exception and getting the message from there may be solution for you if you're interested the single message added in throw error(). But if you're interested in other infolog messages, such as the one coming from warning() or checkFailed(), you won't get it from the exception. The solution in such a case is getting messages from infolog (such as by infolog.copy()).
  • Ken Manhattan Profile Picture
    Ken Manhattan 390 on at
    What is the difference between Microsoft.Dynamics.Ax.Xpp.ErrorException and System.Exception ?
    Hi Martin,
     
    Thanks for your reply. But I guess you're responding while I edit my question. 
     
    So this is my intention of this question :
     
    The main issue is in that Runnable class, and inside a Try..Catch... I'm deleting some record which at some case it is not allowed, for example / Delete purchtable/ while the PO already confirmed. I want to catch the message of the error, in standard or manual delete from the UI, I think it will says /If the previous document exist, cannot delete the record/ or something like that. What do I need to do to catch or get the error message ?
     
    Thanks.
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 228,135 Most Valuable Professional on at
    What is the difference between Microsoft.Dynamics.Ax.Xpp.ErrorException and System.Exception ?
    System.Exception is the parent class that all (more specific) exceptions inherit from, which applies to Microsoft.Dynamics.Ax.Xpp.ErrorException as well.
     
    Which exception you should catch depends on what you want to achieve. If you're using .NET Interop, you may get non-AX exceptions such as InvalidOperationException and System.Exception covers all of them.
     
    Note that the usual way of catching ErrorException is catch (Exception::Error). There are special cases when catching Microsoft.Dynamics.Ax.Xpp.ErrorException is useful, but you won't see it often.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,135 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans