Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

XmlDocument.root().SelectSingleNode() - or error handling in general

(0) ShareShare
ReportReport
Posted on by 555

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.

  • Morten Steengaard Profile Picture
    555 on at
    RE: XmlDocument.root().SelectSingleNode() - or error handling in general

    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().

  • Martin Dráb Profile Picture
    232,850 Most Valuable Professional on at
    RE: XmlDocument.root().SelectSingleNode() - or error handling in general

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,998 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,850 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans