web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Zohan Profile Picture
    2 on at
    RE: Exception handling Error

    Martin it was just an example. anyways thanks.

  • Martin Dráb Profile Picture
    235,804 Most Valuable Professional on at
    RE: Exception handling Error

    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
    RE: Exception handling Error

    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 ?

  • Suggested answer
    Martin Dráb Profile Picture
    235,804 Most Valuable Professional on at
    RE: Exception handling Error

    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".

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
KP-31070522-0 Profile Picture

KP-31070522-0 3

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans