Skip to main content

Notifications

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.");
}

  • Community Member Profile Picture
    on at
    RE: not in catch when exception::Error

    thank you, good iead, I try

  • Suggested answer
    Martin Dráb Profile Picture
    232,114 Most Valuable Professional on at
    RE: not in catch when exception::Error

    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
    RE: not in catch when exception::Error

    Hi Martin Dráb2020_2D00_08_2D00_25_5F00_16_2D00_22_2D00_01.png

  • Martin Dráb Profile Picture
    232,114 Most Valuable Professional on at
    RE: not in catch when exception::Error

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,302 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,114 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans