Click here to Skip to main content
13,352,638 members (36,518 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 30 May 2011

Details on Transactionscope exception handling

, 30 May 2011
Rate this:
Please Sign up or sign in to vote.
How to do transaction scope exception handling.
I think the documentation on TransactionAbortedException is a little lacking as to when it can happen.

It does not happen if you do not do a Scope.Complete on your initial transaction. In other words, failure to execute Scope.Complete means that it will silently exit a transaction scope using block. (Since there is no other way to cancel the transaction scope silently, this is acceptable but should be documented clearly.)
If you need to alert your processes that you are aborting the initial transaction, you should do so by throwing an exception, which will silently close the transaction scope automatically. You may want to have a try/catch wrapping your transaction scope using block to catch these exceptions.

However, if you have multiple same level calls to processes that have their own transaction scope using blocks that join the ambient transaction, you will get an exception if you fail to Scope.Complete on a call. When a subsequent call initiates the transaction scope, it sees a dirty transaction and will issue the transactionabortedexception at that point. However, if you are nesting calls and the child call does not issue a scope.complete, then any other child call open above it will not issue an abort exception when it issues a scope.complete(), it will only be caught if another transaction is attempted or when the initial transasction scope issues a scope.complete.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Brian Risley
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 30 May 2011
Article Copyright 2011 by Brian Risley
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid