Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Not able to catch exce...
Finance forum
Answered

Not able to catch exception in endPost() method

Posted on by 2
Hi,
I am trying to catch an exception in custom code I wrote in extension class of SalesPackingSlipJournalPost.endPost(), I am calling base endPost method first using CoC and trying to generate a custom report at the end of the posting , the issue is that if an error/exception occur in generating/printing of custom report the packing slip posting fails which I don't want to happen, The packing slip posting should not fail if for some reason there is an error/exception in printing custom SSRS report. In this situation I want to catch the exception and display an infolog saying the packing slip is posted but the generation/printing of custom report failed due to xyz reason. 
 
my code look something like this. 
 
public void endPost()
{
   next endPost()
     
     try
     {
          //My code that involve writing to some tables and calling controller class of a SSRS report; some times i get an exception in                     
            meunFunciton.run(args) in one of my custom methods. 
     }
     catch
     {
          //Display Infolog about error
     }
}
 
I am not able to achieve my desired outcome, when the exception occurs system display it in UI and the posting of packing slip is cancelled. 
 
  • CU10090129-0 Profile Picture
    CU10090129-0 4 on at
    Not able to catch exception in endPost() method
    Thanks, Jonas, for your suggestion 
    I moved my code to Post event hander of Run method of SalesFormLetter and it worked. the packing slip posted even if there is an error/exception in the generation/printing of SSRS report. 
     
     
    for some weird reason my question is appearing under some other profile so can't mark your answer as verified answer. but thanks again 
  • Martin Dráb Profile Picture
    Martin Dráb 228,552 Most Valuable Professional on at
    Not able to catch exception in endPost() method
    Moved from D365 general forum to the Finance forum, because it's clearly about F&O and not about D365 in general.
  • Verified answer
    Not able to catch exception in endPost() method
    It's an inherent design of X++. Assuming by the name of the method, it's inside a transaction.

    When an exception occurs within a transaction scope (TTSBEGIN, TTSCOMMIT), it aborts the transaction, and except for a few cases, no try/catch statement inside a transaction scope can process an exception.
     
    I have found a good article about the topic, if you want to learn more: https://www.linkedin.com/pulse/x-exceptions-transactions-michael-pontoppidan/
     
    You will have to rethink how you run your printing.
     
     
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 7,079 Super User 2024 Season 2 on at
    Not able to catch exception in endPost() method
    Hi,
     
    You could try this:
     
    System.Exception ex;
    try
    {
     
    }
    catch(ex)
    {
        error(ex.Message);
    }
     
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,552 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,552 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans