Kevin Trethewey

Software Developer, Technologist, Connoisseur of things that go 'bing'.

  • Home
  • Contact
  • Links
  • About

Exceptional Quiz

Published Sunday, May 09, 2004 8:44 AM
What is the functional difference between the two catch block below?
(There's only one difference)

catch (Exception ex)
{
      throw ex;
}
catch (Exception ex)
{
      throw;
}


If you you know (or are brave enough to admit you are stumped), post in the comments section!

Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!
by Kevin Trethewey

Comments

# Colin said on Sunday, May 09, 2004 10:59 AM

I can't say that I knew that you can use throw by itself in a catch block, but looking at the code, it will generate a warning about unused variables when you compile it.

catch (Exception)
{
throw;
}

will avoid the warning.

# senkwe said on Sunday, May 09, 2004 11:05 AM

If the second statement actually compiles, I'd wager that the two statements are functionally equivalent. I say that because it would be in the language designers best interests to make sure some kind of sensible excpetion is thrown :-) Interesting.

# Mike Groenewald said on Sunday, May 09, 2004 4:05 PM

the lower catch block will not reset the call stack.

# Colin said on Sunday, May 09, 2004 6:02 PM

That's some pretty sneaky stuff...is it documented anywhere? I had a quick look in msdn and didn't see it.

I suppose it's there so that you can preserve the stack trace and still have a finally clause.

# KevinT said on Monday, May 10, 2004 8:25 AM

Mike's got it :-P Well done - u get the...um....ForestBlog Wood of the Week award!

# Armand du Plessis said on Monday, May 10, 2004 8:46 AM

Agree with Mike, second statement will preserve the call stack.

Go

Tags

  • .NET
  • Admin
  • ALT.NET
  • Community
  • Dotnet.org.za
  • eBooks
  • Fonts
  • Free Stuff
  • Fun Stuff
  • Google
  • Links
  • Microsoft
  • Personal OffTopic
  • Quotes
  • Red Five Labs
  • Robotics
  • Software Development
  • South Africa
  • SQL
  • Useful Advice
  • Utilities
  • Video
  • Virtual Post-It
  • Vista
  • VSTS Tips
  • WebDev
  • Wiki

Navigation

  • Home
  • Careers
  • Downloads
  • Support

Archives

  • May 2008 (1)
  • October 2007 (1)
  • July 2007 (1)
  • June 2007 (2)
  • May 2007 (1)
  • February 2007 (2)
  • January 2007 (2)
  • December 2006 (3)
  • November 2006 (9)
  • October 2006 (10)
  • September 2006 (3)
  • August 2006 (2)
  • July 2006 (6)
  • June 2006 (7)
  • May 2006 (9)
  • April 2006 (4)
  • March 2006 (14)
  • February 2006 (2)
  • January 2006 (5)
  • December 2005 (5)
  • November 2005 (7)
  • October 2005 (4)
  • September 2005 (10)
  • August 2005 (3)
  • July 2005 (5)
  • June 2005 (8)
  • May 2005 (11)
  • April 2005 (10)
  • March 2005 (7)
  • February 2005 (11)
  • January 2005 (12)
  • December 2004 (5)
  • November 2004 (2)
  • October 2004 (3)
  • September 2004 (10)
  • August 2004 (13)
  • July 2004 (6)
  • June 2004 (7)
  • May 2004 (24)
  • April 2004 (20)
  • March 2004 (21)
  • February 2004 (19)

Syndication

  • RSS
  • Atom
  • Comments RSS
Powered by Community Server (Commercial Edition), by Telligent Systems