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 :
Microsoft Dynamics AX (Archived)

Get the last error string

(0) ShareShare
ReportReport
Posted on by

How can I know the last error string by using try + catch blocks ?

Thanks :)

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Denis Patrakov Profile Picture
    on at

    You can store the number of lines in the infolog before entering a try block:

    int startLine = infolog.line();

    And in the catch block get all the messages that have been added in the try block:

    str msg;
    int currentLine;
    // ...
    for (currentLine = startLine + 1; currentLine <= infolog.line(); currentLine++)
    {
        msg += infolog.text(currentLine);
    }

    To get only the last message you can use a code like this:

    str msg;
    // ...
    if (infolog.line() > startLine)
    {
        msg = infolog.text();
    }
  • Community Member Profile Picture
    on at

    I think you didn't understand my question.

    I don't know what happens in the try block (It's a 3rd party function - I cannot change - kind of "black-box") but I know that this function throws an exception.

    I want to know what kind of exception (what message, what message-no, if any, etc ...) How can I know that ?

    Thanks :)

  • Denis Patrakov Profile Picture
    on at

    If we are still talking about AX then there are just a few situations when you cannot change the code you're calling from X++ and all of them are related to some kind of interop: COM/.NET/DLL. Is this your case?

  • Community Member Profile Picture
    on at

    We are still talking about AX.

    I don't understand : Can I get the last error string or not? If I can - then how

    (I just need to know what to tell the 3rd party company what error in order to get in progress).

    Thanks :)

  • Verified answer
    Denis Patrakov Profile Picture
    on at

    Yes, you can get but... There can be four main scenarios in your case:

    • You call X++ code - in that case you can use the sample code provided earlier;
    • If you call .NET code - use AifUtil::getClrErrorMessage();
    • If you call a DLL function - use WinAPI::getLastError() or   WinAPIServer::getLastError() and then format the message according to error code;
    • If you invoke a COM object - use COM.getError() to get a COMError object an retrieve the message via COMError.description().

    If you directly call .NET/COM/DLL and try to get the error message from the infolog then you'll get a "stub" message like "An error occurred when invoking CLR class". But if you process an order then you most likely call X++ code so you can just call infolog.text().

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans