Re: Finding out if an exception occurred in a finally block. (.NET 2.0)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Peter wrote:

As I said in my original post, this a simplification of my problem, but my problem is much more complex, so I cannot do as you propose. The fact is, that all my logic handling the transaction is wrapped in a class, that is disposed using the using statement.
But in my transactionhandling's Dispose implementation I want to determine if an exception was thrown


using( TransactionHandling t = new TransactionHandling())
{
}

I understand, but I still think you should handle things differently :-) For example, you could rethrow the exception to be caught outside your transaction handling encapsulation. Or, if you absolutely want to break out of the standard exception handling system, you could store away the exception information in a catch block inside the class and evaluate that information from the outside later on.


I thought I had at some point heard or read something about a way to detect whether "there is currently an exception". But I was unable to find whatever it was I had in mind there. The other thing is: Such a mechanism could obviously only work if the exception was still "active" at that point, in contrast to having been swallowed by a catch block earlier on. So if the exception is really active at this point in your code, what would keep you from simply catching it with a catch block?

What you are asking is, apparently, "how do I find out if an exception was thrown before I got to the point where I'm now". The answer to that will usually be yes, of course, because exceptions are thrown and caught many times during the run of a .NET application (even though we all know they shouldn't be used for flow control in the main execution path). Now you are going to modify the question to say "I'm not interested in all exceptions that might have been thrown before I got to the current point, only in those that might have been thrown during the use of the TransactionHandling class." So if that is your actual question, let me ask again: Why don't you put an external try/catch around the use of the TransactionHandling class and find out?



               Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
.



Relevant Pages

  • BEGIN TRANSACTION problem
    ... there was no BEGIN TRANSACTION. ... The test prior to the exception is the first to execute the parent ... The is the exception the unit test is expecting. ... Rollback statement faile with "The ROLLBACK TRANSACTION request has no ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: HELP on New request is not allowed to start because [1264822]
    ... allowed to start because it should come with valid transaction descriptor. ... System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean ... TRXOrders.CLogin.GetTradexUserIDFromQube(String QubeUserID, String GroupCode) ... This error always occurs when we issue the command to SQL Server. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: CMutex /CEvent (multiple threads)
    ... deals with exception detection. ...  If your function does not handle an exception in Java, ... designer did not understand what a Mutex was and that the notion that Lock could return ... ...roll back transaction ...
    (microsoft.public.vc.mfc)
  • RE: HELP on New request is not allowed to start because [1264822]
    ... "Jeff Glenn" wrote: ... We have posted a simple code reproducing the behavior to Microsoft. ... application doen't raise any exception during a distributed transaction. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Model-View-Presenter (MVP) question
    ... Thanks for your response. ... I still have the problem of handling ... What if an Exception is thrown ...
    (comp.object)