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 :
Microsoft Dynamics AX (Archived)

Exception handling Error

(0) ShareShare
ReportReport
Posted on by 2

Hi,

there's a query related to exceptional handling. In C# or .net we can use try catch method and print our own customized message, but as per dynamics we can't do that . We just throw an exception which generally system generate. I want to know that can we throw our customized message in try catch method ? if anyone have answer then do let me know with example . 

i've searched a class CLRInterpo class but don't know how to consume it in try catch method

*This post is locked for comments

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

    No, you can't throw messages in either .NET or AX.

    In .NET, you can throw exception objects, i.e. instances of classes extending System.Exception. These objects have several properties, such as Message (and StackTrack, InnerException etc.).

    In X++, you throw an exception enum value, such as throw Exception::Error. There is no object with any extra properties (unless you actually execute CIL code generated from X++, which is a bit different case). But you can add messages to infolog when you're throwing an exception. That's exactly what error() function is for - it add a message to infolog and return Exception::Error, which you can use in throw statement (e.g. throw error("My error message").

    Maybe you should explain your scenario, because I don't understand what you mean by saying that "w just throw an exception which generally system generate".

  • Zohan Profile Picture
    2 on at

    Martin

    Consider an example.

    try

    {

      //code logic

    }

    catch(exception::Example)

    {

      throw exception::something

    }

    can we throw our own customised exception ? or just pass exception thorugh info ?

    And what CLRInterpo class is used for ?

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    You can use throw error("Custom error message"). Also note that Exception::Example isn't valid code; the Exception enum type doesn't have any element called Example.

    You can read about CLRInterop class in AX documention.

  • Zohan Profile Picture
    2 on at

    Martin it was just an example. anyways thanks.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans