﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>inoodle commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>Ah, just spotted a potential issue for me at least...
  
Marshal.GetExceptionCode() won't work under asp.net medium trust.
  
Back to delegates :)
  
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment18</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment18</guid><pubDate>Mon, 25 Jun 2007 11:32:38 GMT</pubDate></item><item><title>Bevan Arps commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>Provided this is reliable (something I'm not yet convinced of), this is going to simplify a whole bunch of things in my codebase.
  
  
Interestingly, you could do this in a supported way in Delphi, and I was talking to a friend recently to see if it was possible in .NET.
  
  
I wonder, does referencing Marshal introduce any odd dependencies that wouldn't normally be present? If so, this could explain why MS didn't use it themselves in System.Transactions.
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment17</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment17</guid><pubDate>Wed, 20 Jun 2007 20:36:10 GMT</pubDate></item><item><title>Ayende Rahien commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>I would go with the more explicit syntax reason
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment16</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment16</guid><pubDate>Wed, 20 Jun 2007 19:26:04 GMT</pubDate></item><item><title>John Rusk commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>I wonder why Microsoft did not use this for System.Transactions?  Do they know something we don't?  Did they simply not think of it?  Or, did they discard it because they felt that a more explicit syntax was easier for us to understand?
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment15</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment15</guid><pubDate>Wed, 20 Jun 2007 19:12:30 GMT</pubDate></item><item><title>Ayende Rahien commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>You aren't missing much. That is the intent of the code.
  
The ideas behind With.Transaction, etc are to handle the case of thrown exception, so having a good way to handle that is very nice.
  
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment14</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment14</guid><pubDate>Wed, 20 Jun 2007 14:17:03 GMT</pubDate></item><item><title>Bill Pierce commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>I'm a bit slow to catch on as well.  Is the intention of ExceptionDectector to allow you to dispose differently depending on wether or not an exception was thrown?  I would need a use case to more fully understand this feature.
  
  
@inoodle:
  
I would contend that Within.UnitOfWork is a much clearer syntax, even with delegate { } tacked on the end.
  
  
@Jeff Perrin:
  
What if you do not want to implicitly commit the transaction if no exception is thrown?  The current functionality of SqlTransaction is to implicitly Rollback if no Commit was issued.  I would prefer more descriptive syntaxt like using(Transaction trans = new Transaction(CommitStyle.Implicit)) { }
  
  
What is my feeble brain missing?
  
  
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment13</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment13</guid><pubDate>Wed, 20 Jun 2007 12:38:27 GMT</pubDate></item><item><title>Stefan Wenig commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>ayende, this is what MSDN lib says:
  
  
GetExceptionCode is exposed for complier support of structured exception handling (SEH) only. If called before an exception is thrown, this method returns 0xCCCCCCCC.
  
  
Ok, so firstly, == 0 seems to be wrong. Then, which exception? The last exception on this thread? The innermost exception in the current scope? The exception in the innermost scope? You'd have to make and test a whole lot of assumptions here. 
  
  
What about portability? Mono?
  
  
I have to say I'd rather write VoteToCommit() than build on such weak assumptions...
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment12</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment12</guid><pubDate>Wed, 20 Jun 2007 10:36:15 GMT</pubDate></item><item><title>Jeff Brown commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>One last thought...
  
  
Is this hack portable?  What will Mono do?  I assume it doesn't necessarily implement its exception handling using Win32 SEH.  Therefore I wouldn't be too surprised if the Marshal.GetExceptionCode() method were unimplemented or not meaningful...
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment11</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment11</guid><pubDate>Wed, 20 Jun 2007 09:58:31 GMT</pubDate></item><item><title>Jeff Brown commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>@Jeff Perrin,
  
Yep, I've forgotten Transaction commits too.  Wouldn't it be nice to have Smalltalk blocks in C# instead of these clunky control structures?  Anonymous delegates and even lambdas don't quite cut it.  Oh well.
  
  
Still, the exception detecting using trick will be very useful indeed...  My only concern is that its behavior may surprising to the unwary.
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment10</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment10</guid><pubDate>Wed, 20 Jun 2007 09:21:09 GMT</pubDate></item><item><title>Gokhan commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>Then why don't you write the code in the post using the use case, in the first place?
  
  
There's so much going on in comments on this site, all the time, and you write 187 posts a day, average. When wife and kid start to complain, I'll give them your e-mail :)
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment9</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment9</guid><pubDate>Wed, 20 Jun 2007 07:20:16 GMT</pubDate></item><item><title>Jeff Perrin commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>Derik,
  
  
Previously to do a "using" with a transaction you had to do something like this:
  
  
using(Transaction t = new Transaction()){
  
  //important stuff
  
  t.VoteToCommit();
  
}
  
  
Using this technique it looks like you don't need the VoteToCommit() call, which is good because I always forgot to add that, and then spent hours debugging why my tables weren't being updated. 
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment8</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment8</guid><pubDate>Wed, 20 Jun 2007 04:54:37 GMT</pubDate></item><item><title>Ayende Rahien commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>@Derik,
  
It enable this code:
  
  
using(new Transaction())
  
{
  
  /// blah
  
}
  
  
Where the transaction can decide if it wants to commit or rollback based on the exception status.
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment7</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment7</guid><pubDate>Wed, 20 Jun 2007 04:30:00 GMT</pubDate></item><item><title>Ayende Rahien commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>@inoodle,
  
Absolutely!
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment6</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment6</guid><pubDate>Wed, 20 Jun 2007 04:23:21 GMT</pubDate></item><item><title>Jeff Brown commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>Doh!  Meant within the using statement.
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment5</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment5</guid><pubDate>Wed, 20 Jun 2007 01:11:35 GMT</pubDate></item><item><title>Jeff Brown commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>Oh neat!  Mind that I think it can be fooled...  What happens if your using statement appears within an exception handler?  Will you be able to tell whether the exception occurred within or outside the exception handler?
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment4</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment4</guid><pubDate>Wed, 20 Jun 2007 01:10:53 GMT</pubDate></item><item><title>Derik Whittaker commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>Ok, 
  
  
What am i missing?  In what scenario is this needed?
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment3</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment3</guid><pubDate>Wed, 20 Jun 2007 01:08:05 GMT</pubDate></item><item><title>Alex Henderson commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>That's some sweet stuff :) how come I haven't heard of it until now!
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment2</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment2</guid><pubDate>Wed, 20 Jun 2007 00:56:49 GMT</pubDate></item><item><title>inoodle commented on Did you know: Find out if an exception was thrown from a finally block!</title><description>Ooooo nice one.
  
That puts:
  
using(new UnitOfWork()) {} back on the table - instead of Within.UnitOfWork(anon delegate etc).
</description><link>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment1</link><guid>http://ayende.com/2577/did-you-know-find-out-if-an-exception-was-thrown-from-a-finally-block#comment1</guid><pubDate>Tue, 19 Jun 2007 23:32:01 GMT</pubDate></item></channel></rss>