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, ...
Answered

Different between Error and ThrowError

(0) ShareShare
ReportReport
Posted on by 48

Hi Everyone,

i wonder what is the benefit of using throw error instead of using error in code x++

I have the same question (0)
  • OmarAbdlhamed Profile Picture
    48 on at
    RE: Different between Error and ThrowError

    Thanks Martin :)

  • Verified answer
    Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    RE: Different between Error and ThrowError

    No, I don't. Exceptions and transactions are two different things. Also, there is nothing like "a rollback of all code".

    If you don't even know what an exception is, you need to learn some basics before you can continue. For example, check out Exception Handling with try and catch Keywords in Dynamics AX documentation.

  • OmarAbdlhamed Profile Picture
    48 on at
    RE: Different between Error and ThrowError

    Hello Martin,

    do you mean that throw error works as ttsabort in catch statement and roll back all code ?

  • Verified answer
    Martin Dráb Profile Picture
    235,979 Most Valuable Professional on at
    RE: Different between Error and ThrowError

    throw error() throws an exception, therefore it breaks code execution.

    error() just adds an error message to infolog, but it doesn't throw an exception. Code execution continues normally.

    You can easily open error() method to see what it does. You'll see that it adds a message to infolog and returns Exception::Error value. That's all.

    When you use throw error(), it means that you call error() to add an error message to infolog and then throw what the method returns. Therefore it's an equivalent of this:

    error("A message");
    throw Exception::Error;

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

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

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 882 User Group Leader

#2
André Arnaud de Calavon Profile Picture

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

#3
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 518

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans