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, ...
Suggested Answer

x++ code do not enter catch block with DataHandlerEvent handler

(0) ShareShare
ReportReport
Posted on by 5

i am new to x development and used to write java program . i just get confused with try catch in x , please help me 

    public static void main(Args _args)
    {

        try
        {
            int p = 9;
            p = p   9;
            throw error(" error occured ");
        }
        catch{

            int i = 8;
            info("in catch ");
        }finally
        {
            info("in finally ");
        
        }
        info(" out of try catch ");

    }

if i run the code above in main method i can get all the message in page like below and that's what i expected

pastedimage1671485012867v2.png

error occured
in catch
in finally
out of try catch

but when i use the try catch in DataEventHandler message in catch are not be shown 

    [DataEventHandler(tableStr(DataTransfer), DataEventType::Inserted)]
    public static void DGDwDataTransfer_onInserted(Common sender, DataEventArgs e)
    {
        if(data.Direction == Direction::CE2FO)
        {
            SysInfoLogEnumerator infoLogEnum;
            SysInfologMessageStruct infoMessageStruct;
            str integrationMessage;
            try
            {
                int p = 9;
                p = p   9;
                throw error(" error occured ");
            }
            catch
            {

                int i = 8;
                info("in catch ");
            }
            finally
            {
                info("in finally ");
        
            }
}
}

pastedimage1671484981302v1.png

I have the same question (0)
  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    Hi Kevin,

    Exception inside the transaction cannot be catch since you are adding the code on inserted event handler.

    Refer to the below documentation.

    learn.microsoft.com/.../exception-handling-with-try-and-catch-keywords

    Thanks,

    Girish S.

  • kevinAAA Profile Picture
    5 on at

    Hi Girish thank you very much.  your remarks helped me a lot.   i am developing a progam to create sales order when data inserted. and data is come from Dual write from CE system .   As you tell if exception is thrown in Inserted Event (transaction)  i can not catch the exception so excpetion will be thrown to outer method which will roll back DualWrite's Data Insert action.  are there some way to prevent the roll back action ?  I need to make sure that CE's data can be inserted with no problem.

    I don't has much knowledge to finance and operation . I really appreciate your help  

  • GirishS Profile Picture
    27,827 Moderator on at

    From my understanding I don't think there is a way to prevent roll back if there is an error occurred inside transaction.

    Wait for some other community members to have an idea on this.

    Thanks,

    Girish S.

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
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans