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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Why are my x++ exceptions not being caught d365fo

(3) ShareShare
ReportReport
Posted on by 271
I created the following method for sending emails:
 
    public static void sendEmail(str templateId, str emailTo, Map templateToken)
    {
        Email   emailFrom, subjectTxt;
        str     emailFromName, emailBody;
        var mailer          = SysMailerFactory::getNonInteractiveMailer();
        var messageBuilder  = new SysMailerMessageBuilder();
        [subjectTxt, emailBody, emailFrom, emailFromName] =
                SendEmailHelper::getEmailTemplate(templateId);

        if (emailTo != '')
        {
            System.Exception e;
            try
            {
                messageBuilder.reset()
                 .addTo(emailTo)
                 .setSubject(subjectTxt)
                 .setBody(SysEmailMessage::stringExpand(
                    emailBody, SysEmailTable::htmlEncodeParameters(templateToken)))
                    .setFrom(emailFrom);
                mailer.sendNonInteractive(messageBuilder.getMessage());
            }
            catch(e)
            {
                Error(strFmt("Error: %1", e.ToString()));
            }
        }
    }
But the problem when the sender user doesn't have the permission for sending the email sendNonInteractive method throw error, but it isn't caught in the catch clause despite using the parent class of all exceptions, can you please tell me what may be the reason?
It seems as if the exception is swallowed or rethrown in the catch clause but basically it doesn't enter the catch clause
Email error - Copy.PNG
I have the same question (0)
  • Verified answer
    Jonas "Jones" Melgaard Profile Picture
    4,988 Most Valuable Professional on at
     
    Have you checked if this code is being called inside of a transaction (TTS) scope?
    If so, only a few handful exceptions related to transaction integrity can be caught.
     
     
    Edit: I see you have added the exact exception, and now see it's related to .net. My assumption about TTS might be incorrect, if so Martin wrote a really great article about handling different kinds of exceptions thrown by .net: https://dev.goshoom.net/2017/06/catching-exceptions-in-ax-7/
  • MS-29011540-0 Profile Picture
    271 on at
    Hello @ ,
    Thanks for your reply
    I think your assumption of that the code may be used in TTS is correct because i use it in OnUpdating eventhandler for ledgerJournalTable,
    I use the code on OnUpdating methpd to be able to check the orig buffer with the current buffer to check if the journal is posted or not

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans