web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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.

I have the same question (0)
  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    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.

  • Morten Steengaard Profile Picture
    555 on at

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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 669 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 384 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans