How can I know the last error string by using try + catch blocks ?
Thanks :)
*This post is locked for comments
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(); }
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 ?
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?
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).
Yes, you can get but... There can be four main scenarios in your case:
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Community Member 4
Guy Terry 2 Moderator
Nayyar Siddiqi 2