web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

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

(0) ShareShare
ReportReport
Posted on by 552
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
 
 
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    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.
  • Ken Manhattan Profile Picture
    552 on at
    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
    237,801 Most Valuable Professional on at
    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
    552 on at
    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);
    }
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    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
    552 on at
    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)
     
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    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().

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans