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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Why my error log contain old error message ?

(0) ShareShare
ReportReport
Posted on by

Hi guys,

In my Catch error, I usually write like this : 

 catch (Exception::Error)
        {
            Str1260         errorTxt = "";
            int i;
            for (i=1; i<=Global::infologLine(); i  )
            {
                infolog.text(i);
                errorTxt  =  errorTxt   ";/n"   infolog.text(i);
            }
            
            .
            .
            .
        }

Then usually I will get that variable errorTxt and insert into my Log table (or just display on screen)

Question is why the errorTxt can contain old error message which is not from my current process ? how to clear the previous and only get the error message of current process ?

An example for this is, before I'm running my process, I'm open some other form and hit some standard error, then few minutes later I'm testing my code, ran and hit some error, but the error message will be started with the previous error before I'm running my code.

Thanks,

I have the same question (0)
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    RE: Why my error log contain old error message ?

    Can you try clearing the error by clicking clear in vs?

  • VoltesDev Profile Picture
    on at
    RE: Why my error log contain old error message ?

    you mean like this :

    infolog.clear()

  • Suggested answer
    huijij Profile Picture
    19,811 on at
    RE: Why my error log contain old error message ?

    Hi VoltesDev,

    The Global::infologLine() method is used to gets the number of error lines in the Infolog buffer. If you want to get the error message of current process, you can check the MS document about X++ exception handling:

    learn.microsoft.com/.../xpp-exceptions

  • Suggested answer
    Mohit Rampal Profile Picture
    12,563 Moderator on at
    RE: Why my error log contain old error message ?

    Hi VoltesDev, We are using below code to capture infolog errors. Please check if it helps you.

    protected str getMessagesFromInfoLog()
    {
        SysInfologEnumerator enumerator;
        SysInfologMessageStruct msgStruct;
        Exception exception;
        str error;
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            error = strfmt("%1 %2", error, msgStruct.message());
            
        }
        
        infolog.clear();
    
        return error;
    }

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    RE: Why my error log contain old error message ?

    Hi, please debug the issue. It is supposed to give new error as it is a local variable. So, try debugging and check what buffer is present in errorTxt at line 3 (it should be empty) and check how it is changing at line 8.

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 580 Most Valuable Professional

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 554

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans