That is what I have on the code... What I need now is do detect from the Rollback Transaction method wether or not an error has occurred. To be more clear, this is the scenario that I have:
BusinessComponent::DoSomethingThatRequiresTransactions() DataComponentA::DoSomething(); DatabaseOperator.Commit();
{
DatabaseOperator.BeginTransaction(KnownDatabases.Global);
DataComponentB::DoSomethingElse();
}
catch
{
DatabaseOperator.Rollback();
throw;
}
DataComponentA::DoSomething() ExecuteProcedure(); DatabaseOperator.Commit();
{
DatabaseOperator.BeginTransaction(KnownDatabases.Global);
ExecuteAnotherProcedure();
}
catch
{
DatabaseOperator.Rollback();
throw;
}
In this scenario if DataComponentA performs rollback transaction everything will be OK, but if BusinessComponent tries to do a Rollback again (in a nested transaction) then we have the problem of my question. How can I know that there is an error in the thread. Is there a way to know this?
I take it this isn't a .Net transaction othewise you tell from the transaction object whether its been rolled back e.g.
if (transaction.TransactionInformation.Status == TransactionInformation.Aborted)
{
...
}
Duncan
You'll have to set at flag or something in your catch block.
Juan Roman wrote:
That is what I have on the code... What I need now is do detect from the Rollback Transaction method wether or not an error has occurred. To be more clear, this is the scenario that I have:
BusinessComponent::DoSomethingThatRequiresTransactions()
{
DatabaseOperator.BeginTransaction(KnownDatabases.Global);DataComponentA::DoSomething();
DataComponentB::DoSomethingElse();DatabaseOperator.Commit();
}
catch
{
DatabaseOperator.Rollback();
throw;
}DataComponentA::DoSomething()
{
DatabaseOperator.BeginTransaction(KnownDatabases.Global);ExecuteProcedure();
ExecuteAnotherProcedure();DatabaseOperator.Commit();
}
catch
{
DatabaseOperator.Rollback();
throw;
}
In this scenario if DataComponentA performs rollback transaction everything will be OK, but if BusinessComponent tries to do a Rollback again (in a nested transaction) then we have the problem of my question. How can I know that there is an error in the thread. Is there a way to know this?
So there is no information in the thread, the stack trace, the app domain that states if an untrapped exception has occurred?
If it's un-trapped your application exits. I don't know if the ApplicationExit event is raised; but, it doesn't have any included information about why the application exited.
Juan Roman wrote:
So there is no information in the thread, the stack trace, the app domain that states if an untrapped exception has occurred
Won't be triggered if you are mean that the exception isn't handled for a couple of tiers of the stack but is handled lower down.
Yes, there is the UnhandledException event; but, the application is still terminating.
Duncan Woods wrote:
There are events on the Application and AppDomain for entirely unhandled exceptions.
Won't be triggered if you are mean that the exception isn't handled for a couple of tiers of the stack but is handled lower down.
The UnhandledException event is on the AppDomain object; there can be more than one AppDomain per process, this event is only raised for the AppDomain created by the CLR upon invocation of the application. Your application will be in an unknown state when this event is raised, there's not much you can reliably do when handling this event.
There's also the ThreadException event on the Application object that will get raised if an untrapped exception is raised on a thread. As the documentation describes; your thread will be in an unknown state--there's not much you can reliably do in this event handler. It signals that your thread is about to terminate.
[Edit: To be clear; in these event handlers you wouldn't have access to an object to call RollbackTransaction, and quite possibly the object may have already been disposed/finalized.]