web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
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. 
 
I have the same question (0)
  • Suggested answer
    Layan Jwei Profile Picture
    8,282 Super User 2026 Season 2 on at
    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
  • Verified answer
    Jonas "Jones" Melgaard Profile Picture
    5,016 Most Valuable Professional on at
    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.
     
     
  • Martin Dráb Profile Picture
    240,534 Most Valuable Professional on at
    Moved from D365 general forum to the Finance forum, because it's clearly about F&O and not about D365 in general.
  • OS-31101617-0 Profile Picture
    10 on at
    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 

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 341 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 312

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 262 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans