Re: How To Tell You're Within An Exception?
- From: "Günter Prossliner" <g.prossliner/gmx/at>
- Date: Wed, 19 Nov 2008 13:50:00 +0100
Hello Axel!
I've created a Transaction object which is supposed to be used like
this:
using (Transaction transaction = new Transaction())
{
...
}
In the Dispose() method of the Transaction object I want to call
Rollback() if the current process is currently unwinding an exception
stack. If the current process is just reaching the closing brace in
normal program flow, I want to call Commit() within the Dispose()
method.
I already thought that you plan to do something like this. I've also
developed a very similar thing. My solution was to call a method right
before the using(){} block is finished:
(pseudo-code)
using(Transaction t = new Transaction()){
// perform commands
t.SetComplete(); // executing commands after .SetComplete() is not
supported => NotSupportedException
}
Transaction.Dispose() {
if(Complete){
Commit();
} else {
Rollback();
}
}
It is very straight forward, and the developer can control this process.
Allthough in most cases you may rollback on error and commit on success,
this is not always the case. By using the "Exception dedection" Rollback can
only be triggered by an Exception.
There may be possiblities to tell if you're in a Exception by reading the
right CLR's memory ranges. But this may be just something for debugging
purposes, doing this every time you complete an Exception would be an hugh
overhead, and it's totally unsupported.
Maybe you can also take a look a System.Transactions which implements the
whole TX-Framework (it works very similar like your posted Code
(TransactionScope Class)).
e.g.:
using(TransactionScope txScope = new TranscationScope()){
// create sQL Connection, execute commands or whatever
// if a resource is implemented by System.Transactions it will
participate in the TX
txScope.Complete();
}
If needed (when you speak about not ADO.Net Transaction but you have an own
Resource-Type) you may integrate into System.Transactions this is possible
by implementing an Resource-Manager.
OK?
GP
.
- Follow-Ups:
- Re: How To Tell You're Within An Exception?
- From: Axel Dahmen
- Re: How To Tell You're Within An Exception?
- References:
- How To Tell You're Within An Exception?
- From: MSDN-Newsserver
- Re: How To Tell You're Within An Exception?
- From: Günter Prossliner
- Re: How To Tell You're Within An Exception?
- From: Axel Dahmen
- Re: How To Tell You're Within An Exception?
- From: "Jialiang Ge [MSFT]"
- Re: How To Tell You're Within An Exception?
- From: Axel Dahmen
- How To Tell You're Within An Exception?
- Prev by Date: Re: How To Tell You're Within An Exception?
- Next by Date: TypeBuilder CreateType() slow with the VS2008 debugger attached
- Previous by thread: Re: How To Tell You're Within An Exception?
- Next by thread: Re: How To Tell You're Within An Exception?
- Index(es):
Relevant Pages
|
Loading