Skip to main content

Notifications

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
    }
}

  • Suggested answer
    Martin S. Dev Profile Picture
    Martin S. Dev 5 on at
    RE: Exception handling in nested methods (X++)

  • Martin S. Dev Profile Picture
    Martin S. Dev 5 on at
    RE: Exception handling in nested methods (X++)

    Hi,

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

  • Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    RE: Exception handling in nested methods (X++)

    Hi Partner,

    The following forum should be correct:

    (+) Dynamics 365 Finance Forum - Support & Help 

  • Martin S. Dev Profile Picture
    Martin S. Dev 5 on at
    RE: Exception handling in nested methods (X++)

    Hi Leah Ju,

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

  • Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    RE: Exception handling in nested methods (X++)

    Hi Partner,

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

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,971 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,846 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans