Hi Everyone,
i wonder what is the benefit of using throw error instead of using error in code x++
Hi Everyone,
i wonder what is the benefit of using throw error instead of using error in code x++
Thanks Martin :)
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.
Hello Martin,
do you mean that throw error works as ttsabort in catch statement and roll back all code ?
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;
Abhilash Warrier
565
Martin Dráb
536
Most Valuable Professional
André Arnaud de Cal...
402
Super User 2025 Season 1