Partager via


X++ Standards: try/catch Statements

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

Always create a try/catch deadlock/retry loop around database transactions that might lead to deadlocks.

Whenever you have a retry, all the transient variables must be set back to the value they had just before the try. The persistent variables (that is, the database and the Infolog) are set back automatically by the throw that leads to the catch/retry.

Example

    try
    {
        this.createJournal();
        this.printPosted();
    }
    catch (Exception::Deadlock)
    {
        this.removeJournalFromList();
        retry;
    }

See also

Exception Handling with try and catch Keywords

X++ Coding Standards

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.