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

not in catch when exception::Error

(0) ShareShare
ReportReport
Posted on by

Hi all, help me (ax2012)

I post product receipt by code but not catch when error

try

{

purchFormLetter.run();

//error not catch ?

}

}
catch(exception::Error)
{
ttsabort;
result = false;
error("Catch an error exception.");
}

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

    Please use Insert > Insert Code (in the rich-formatting view) to paste source code. It preserves indentation, making code easier to read. Like this:

    try
    {
    	purchFormLetter.run();
    	//error not catch ?
    }
    }
    catch(Exception::Error)
    {
    	ttsabort;
    	result = false;
    	error("Catch an error exception.");
    }

    Then please explain your problem.

    I see you have an extra } there (at line 5 or 6). Don't use ttsabort - throwing an exception aborts transactions, therefore this isn't needed.

    Note that if you catch statement is inside a transaction, it'll be never called. The system aborts transactions and continues execution after the top-level transaction, therefore you must place your try/catch there.

  • Community Member Profile Picture
    on at

    Hi Martin Dráb2020_2D00_08_2D00_25_5F00_16_2D00_22_2D00_01.png

  • Suggested answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Unfortunately your screenshot doesn't show the critical piece of information - whether your catch statement is inside a database transaction or not. There may be a transaction somewhere in the code calling generateProductReceipt().

    One way how to find it out is putting a breakpoint at the beginning of generateProductReceipt(), running the code with debugging and observing TtsLevel in the Autos window (Debug > Windows > Autos). If it's higher than zero, you're inside a transaction and you can't catch errors.

  • Community Member Profile Picture
    on at

    thank you, good iead, I try

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 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans