Announcements
Hi experts,
I have a class that call various classes in AX 2009. It handles all the files in an folder.
I would like to catch all errors that may come from these classes, but some errors are not caught by try-catch {}
For instance, if an xml file is incorrect when I read it, the call to XmlDocument.root().SelectSingleNode(...) is giving an error message that translated to English must be something like: "Error when running code: The object is not initialized".
I could make an if sentence to find and handle that error, but is there a way to catch all the various errors, that my classes can make?
It seems that the error stops the program from running. Is there a way to handle the various exceptions and then go on with the next file in the folder?
Is the text from XmlDocuement an exception?
Hope you can help.
Hi Martin.
Thank you for your reply.
I have tried with your code and with a catch block without mentioning any exception type:
try
{
...
}
catch
{
info('1');
throw error(AifUtil::getClrErrorMessage());
}
info('2');
The error is not caught in any catch block. Info 1 and info 2 is never shown. The program breaks and my best guess is that the error message is not an exception, but something else from the kernel.
When I in the try block call the sub-class, that makes the error message, the TTS level is 0. It is also 0 when the error is made when calling SelectSingleNode().
You should be able to catch CLR exceptions by code like this:
try { ... } catch (Exception::CLRError) { throw error(AifUtil::getClrErrorMessage()); }
Please give it a try.
And of course, make sure that you aren't trying to catch exceptions inside a transaction.
André Arnaud de Cal...
293,998
Super User 2025 Season 1
Martin Dráb
232,850
Most Valuable Professional
nmaenpaa
101,158
Moderator