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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

AX7 how to catch XPP exception object (Microsoft.Dynamics.Ax.Xpp.ErrorException)

(1) ShareShare
ReportReport
Posted on by

Hello community,

I am looking to catch the X++ exception object similar to C# "Catch (System.Exception _e)".

When debugging the catch block I can see a new object has been added to the Locals pane.

Name: $exception

toString:{"<Error text goes here>"}

Type: Microsoft.Dynamics.Ax.Xpp.ErrorException

Is this an object that I can access with X++ in the catch block?

I am very interested in retrieving the stack trace that lead to the exception being thrown.

Best Regards,

Cody P

*This post is locked for comments

I have the same question (0)
  • Mea_ Profile Picture
    60,286 on at

    Hi Cody,

    You can try next code:

    try
    {
        throw Exception::Error;
    }
    catch
    {
        info(con2Str(xSession::xppCallStack()));
    }


  • Community Member Profile Picture
    on at

    xppCallStack() does not solve the problem.

    A typical use case would be to call more complex logic inside the try block (e.g SalesFormLetter.update()).

    xppCallStack will show me that SalesFormLetter.update() was the last line called in the try block before the exception, but does not know about the calls inside SalesFormLetter.update().

    $exception has call that threw the exception, I just need to know if/how to access it.

    Best Regards,

  • Community Member Profile Picture
    on at

    Hi Cody,

    We have the exact same problem at an integration project. Did you find any answer on this?

    Regards,

    Yakup

  • Verified answer
    Martin Dráb Profile Picture
    239,938 Most Valuable Professional on at

    X++ doesn't use objects for exceptions, so it obviously can't have any syntax for working with them. If you throw an error, the only data you can provide is the value of the Exception enum, i.e. a number. Throw error("Error message") is the same as calling throw Exception::Error and putting "Error message" to infolog.

    What you see it the consequence of the fact that CIL has a completely different approach to exceptions than X++ - it uses objects, not the Exception enum, therefore it must create an exception object under the hood.

    Therefore you can't get it from X++; you would have to find some hack how to extract the information from CLR.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sanhthosh.Kumar.K Profile Picture

Sanhthosh.Kumar.K 2

#2
Raed Salah Bzour Profile Picture

Raed Salah Bzour 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans