Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Exception handling Error

(0) ShareShare
ReportReport
Posted on by

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

  • Zohan Profile Picture
    Zohan on at
    RE: Exception handling Error

    Martin it was just an example. anyways thanks.

  • Martin Dráb Profile Picture
    Martin Dráb 230,458 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
    Zohan 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
    Martin Dráb 230,458 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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans