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, ...
Suggested Answer

Exception handling in nested methods (X++)

(0) ShareShare
ReportReport
Posted on by 5

Hello,

Currently, classes with several exception handling code blocks are giving us some problems. The process can occasionally succeed while also failing occasionally for no apparent reason (no infolog). Following a code analysis, we discovered that the problem revolved around a section of code that consisted of nested exception handling practices. As you can see from the code below, there is one major try/catch statement that has a number of smaller ones inside of it. Additionally, we have a method that essentially has the identical statements as the primary method within the nested try statement. Given this, I was debating the proper course of action in cases like this. Should I get rid of the particular clauses and just use the main method's generic one instead?

public void firstMethod()
{
    while (...)
    {
        try
        {
            // Validations
            
            try
            {
                // My code
                this.secondMethod();
                // My code
            }
            
            catch (Exception::Deadlock)
            {
                // My code
            }
            
            catch (Exception::UpdateConflict)
            {
                // My code
            }
            
            catch (Exception::DuplicateKeyException)
            {
                // My code
            }
            
            catch (Exception::Error)
            {
                // My code
            }
            
            catch
            {
                // My code
            }
        }
        
        catch (Exception::Error)
        {
            // My code
            continue;
        }
    }
}

public void secondMethod()
{
    try
    {
        // My code
    }
    
    catch (Exception::Deadlock)
    {
        // My code
    }
    
    catch (Exception::UpdateConflict)
    {
        // My code
    }
    
    catch (Exception::DuplicateKeyException)
    {
        // My code
    }
    
    catch (Exception::Error)
    {
        // My code
    }
    
    catch
    {
        // My code
    }
}

I have the same question (0)
  • Leah Ju Profile Picture
    Microsoft Employee on at

    Hi Partner,

    Could you tell me what app you are using in D365?

  • Martin S. Dev Profile Picture
    5 on at

    Hi Leah Ju,

    We're currently still using AX CRM and 365 FinOps.

  • Leah Ju Profile Picture
    Microsoft Employee on at

    Hi Partner,

    The following forum should be correct:

    (+) Dynamics 365 Finance Forum - Support & Help 

  • Martin S. Dev Profile Picture
    5 on at

    Hi,

    Is there a way to move this thread or should I create a new one?

  • Suggested answer
    Martin S. Dev Profile Picture
    5 on at

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 June Top 10 Community Leaders

These are the community rock stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 433 Super User 2026 Season 1

#2
Subra Profile Picture

Subra 382

#3
Martin Dráb Profile Picture

Martin Dráb 279 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans