Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

not in catch when exception::Error

Posted on by Microsoft Employee

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
    Community Member Microsoft Employee on at
    RE: not in catch when exception::Error

    thank you, good iead, I try

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 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
    Community Member Microsoft Employee 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
    Martin Dráb 230,214 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans