RSS

Exceptions Inside Transactions

20 Jan

When an exception is thrown inside a transaction, the transaction is automatically aborted (a ttsabort operation occurs). This applies both for exceptions thrown manually and for exceptions thrown by the system.

If an exception is thrown inside a ttsBegin/ttsCommit block, it will be caught by the first matching catchlist that is outside the transaction block. If there is a catch block within the ttsBegin/ttsCommit, it will be ignored

 

Example

Example  shows how an exception in a ttsBegin/ttsCommit block is caught by the first catchlist outside the block rather than by the catch within the ttsBegin/ttsCommit block. If you run this code, “outside tts” will be printed before an Infolog displays “Message”.

try

{

ttsbegin;

try

{

throw error(“Message”);

}

catch

{

print “not here”;

pause;

}

ttscommit;

}

catch

{

print “outside tts”;

pause;

}

 

Source: http://msdn.microsoft.com/en-us/library/aa893385(AX.10).aspx

Advertisements
 
2 Comments

Posted by on January 20, 2011 in AX, Basics, Dynamics, SQL, Tables, X++

 

Tags: , , , , , ,

2 responses to “Exceptions Inside Transactions

  1. SebDra

    February 7, 2011 at 11:41 pm

    BUT you can catch two exceptions!
    the updateConflict and the duplicateKey

     
    • Zeeshan Haider Jafry

      February 8, 2011 at 8:38 am

      Yes, you can catch the two exceptions that you mention in case if the catch is written outside the transaction boundary. if it is inside, it will be ignored.
      Thanks for your comment.

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: