Search Options
close
Search the following clips:
All Clips
Everyone's Clips
My Guides
Sign Up
Install
Learn More
Login
Try/Finally Pattern - Take a different path when an exception has occurred.
travislaborde
follow
0
4-9-2008 7:46 AM
144 views
tags:
programming
,
.net
travislaborde
says:
nice
Add a Comment
Login
to Comment. Not a member yet?
Sign up
Related Clips
Harvard Researchers Create Computer Langua...
ComCast Hears You and Talks Back
Creative Code: 14 Ways to Learn From Creat...
FOSSwiki
FreeBookZone - free eBooks
Goodbye To Faulty Software?
Which Linux distribution should I use
More clips from
travislaborde
Talula Does The Hula From Hawaii
Japanese iPhones Get Exclusive Feature to...
Unit Test Boundaries
Today's Top Clips
Complete dinosaur skeleton found in Mongolia
That "do you have any Grey Poupon" joke is officially over
Should have killed him
YOU JUST GOT SCREWED and Nobody Will tell you! URGENT!!
Will Space-Based Solar-Powered Lasers Solve Our Energy Future?
The World´s Most Overlooked Dictators
Geologic Evidence of the Cause of Global Warming and Cooling
Scientists Find the Trigger of the Northern Lights
Convicted killer’s last words before execution: Vote Obama
Wackiest Trucks
visit the
Top Clips page
View the Top Clips from
April 9, 2008
Embed This Clip In Your Site...
<div style="margin: 12px 0px; font-family: arial; color: #333333; background: #ffffff; border: solid 4px #e5e5e5; width: 100%; clear: left;"><div class="CM_CTB_Content_Wrap" style="margin: 0px; padding: 0px;background-color: #ffffff;"><div style="border-bottom: solid 1px #dcdcdc; white-space: nowrap; margin-bottom: 8px; background-color: #eeeeee ;background-image: url(http://clipmarks.com/images/source-bg.gif); background-repeat: repeat-x; height: 24px; line-height: 24px; vertical-align: middle; padding-bottom: 4px; color: #666666; font-size: 10px;" ><a href="http://clipmarks.com/clip-to-blog/" title="see clips that are hot right now"><img src="http://content.clipmarks.com/blog_embed/0e604a80-0dd3-45e4-96c0-d864e1ffbda0/47F9BED0-C405-4345-B736-C5830C9F6C16/" alt="" width="19" height="19" border="0" style="vertical-align: middle; margin: 0px 4px; display: inline; border: none; float:none;" /></a>clipped from <a title="http://geekswithblogs.net/akraus1/archive/2008/04/08/121121.aspx" href="http://geekswithblogs.net/akraus1/archive/2008/04/08/121121.aspx" style="font-size: 11px;">geekswithblogs.net</a></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://geekswithblogs.net/akraus1/archive/2008/04/08/121121.aspx"><H2> <A href="http://geekswithblogs.net/akraus1/archive/2008/04/08/121121.aspx" title="Title of this entry." id="viewpost_ascx_TitleUrl">Try/Finally Pattern - Take a different path when an exception has occurred.</A> </H2></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://geekswithblogs.net/akraus1/archive/2008/04/08/121121.aspx"><P>Error handling is a difficult beast to get right. And there is always one more way to do it. <A href="http://blogs.msdn.com/thottams/archive/2008/03/24/handling-throwing-exceptions-and-clean-up-on-error.aspx">Thottam Sriram</A> did write some nice examples what main cases you usually have to deal with. The most ugly case is the one where you cannot handle an exception but you need to do different cleanup logic in a finally block.</P></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://geekswithblogs.net/akraus1/archive/2008/04/08/121121.aspx"><P><SPAN>public</SPAN> <SPAN>static</SPAN> <SPAN>class</SPAN> <SPAN>ExceptionHelper</SPAN></P> <P> {</P> <P> <SPAN>///</SPAN><SPAN> </SPAN><SPAN><summary></SPAN></P> <P> <SPAN>///</SPAN><SPAN> Check if we are in a exception unwind scenario or not.</SPAN></P> <P> <SPAN>///</SPAN><SPAN> </SPAN><SPAN></summary></SPAN></P> <P> <SPAN>public</SPAN> <SPAN>static</SPAN> <SPAN>bool</SPAN> InException</P> <P> {</P> <P> <SPAN>get</SPAN> </P> <P> {</P> <P> <SPAN>return</SPAN> <SPAN>Marshal</SPAN>.GetExceptionPointers() == <SPAN>IntPtr</SPAN>.Zero ? <SPAN>false</SPAN> : <SPAN>true</SPAN>;</P> <P> }</P> <P> }</P> <P> }</P></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://geekswithblogs.net/akraus1/archive/2008/04/08/121121.aspx"><P><SPAN>public</SPAN> <SPAN>void</SPAN> ImprovedFunc()</P> <P> {</P> <P> <SPAN>try</SPAN></P> <P> {</P> <P> OtherFunc();</P> <P> }</P> <P> <SPAN>finally</SPAN></P> <P> {</P> <P> <SPAN>if</SPAN> (<SPAN>ExceptionHelper</SPAN>.InException)</P> <P> {</P> <P> <SPAN>// perform cleanup on error</SPAN></P> <P> }</P> <P> <SPAN>else</SPAN></P> <P> {</P> <P> <SPAN>// Do normal cleanup in non exception case</SPAN></P> <P> }</P> <P> }</P> <P> }</P></blockquote></div><div style="margin: 0px 6px 6px 4px;"><table style="font-size: 11px;border-spacing: 0px;padding: 0px;" cellpadding="0" cellspacing="0" width="100%"><tr><td style="background:transparent;border-width:0px;padding:0px;"> </td><td align="right" style="background:transparent;border-width:0px;padding:0px;width:107px" width="107"><a href="http://clipmarks.com/share/47F9BED0-C405-4345-B736-C5830C9F6C16/blog/" title="blog or email this clip"><img src="http://content9.clipmarks.com/images/c2b-foot.png" border="0" alt="blog it" width="107" height="17" style="border-width:0px;padding:0px;margin:0px;" /></a></td></tr></table></div></div>
Clipmarks
Home
New Clips
Top Clips
Dashboard
Popular Topics
News
Life
Science
Technology
Entertainment
Get Started
Sign Up
Install Clipping Tool
How Clipping Works
Clip-to-Blog™
ClipSearch
Tools and Resources
FAQ
ClipWeek
Top Clippers
Top Tags
Site Map
About Clipmarks
About Us
Contact
Blog
Copyright
Privacy
EULA
OK