Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Not able to catch exception in endPost() method

(1) ShareShare
ReportReport
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 230,370 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,347 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

News and Announcements

Announcing Category Subscriptions!

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans