CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeremy D. Miller -- The Shade Tree Developer

Under the hood and working with .Net, TDD, Software Design, and Agile Stuff

You know it's a bad day when...

...merely changing the exception being thrown is a minor victory

I do so enjoy working with someone else's very elaborate code for the first time. 



Comments

Eric Wise said:

My personal favorite is some code I was recently supporting which had try catch blocks littered through each step of the code that did the following:

try

{

  // blah

}

catch (exception ex)

{

 throw new exception(ex.message);

}

Now where did that error come from?  You tell me. =)

# December 26, 2006 2:30 PM

Jeremy D. Miller said:

Sigh.  There's so many ways to go wrong even when you're trying.  That one is just self-defeating.

I think one of the very first things new .Net developers should be taught is the difference between

throw;

and

throw ex;

# December 26, 2006 2:43 PM

ScottBellware said:

Yeah, but look on the bright side, Eric... At least the error message won't have that ugly stack trace when it gets thrown up into the AppDomain and added to the Windows event log.  I mean, sheesh, you can't expect developers to waste their time on catching top-level exceptions just to pretty-up the error messages! <g>

# December 26, 2006 8:49 PM

Zack Jones said:

Ok, I'll ask:

What's the difference between

throw;

and

throw ex;

# January 23, 2007 6:33 PM

Jeremy D. Miller said:

Zack,

"throw ex" rewinds the stack trace.  It's as if the exception was thrown from this point to begin with.

"throw" simply sends the exception back on its way until it's handled, but the original stack trace is preserved.

It's a big deal because you can potentially lose contextual information about the exception that could be vital to diagnosing the problem.

# January 23, 2007 9:10 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Jeremy D. Miller

Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy previously worked as a systems architect building mission critical supply chain software for a Fortune 100 company and learned agile development practices as a .Net consultant at ThoughtWorks, one of the pioneers of agile development. Jeremy is the author of the open source StructureMap (http://structuremap.sourceforge.net) tool for Dependency Injection with .Net and the forthcoming StoryTeller (http://storyteller.tigris.org) tool for supercharged FIT testing in .Net. Jeremy's thoughts on just about everything software related can be found on his weblog "The Shade Tree Developer" at http://codebetter.com/blogs/jeremy.miller, part of the popular CodeBetter site. Jeremy is a Microsoft MVP for C#. Check out Devlicio.us!

This Blog

Syndication

News

All opinions expressed here constitute my (Jeremy D. Miller's) personal opinion, and do not necessarily represent the opinion of any other organization or person, including (but not limited to) my fellow employees, my employer, its clients or their agents.

About Me

"Best Of" Compendium

StructureMap (Dependency Injection for .Net)

StoryTeller (Supercharged Fit)

Build your own Cab

TestDriven

MVP