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

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
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans