Here’s a code gem I found yesterday …

try
{
    ...
}
catch (Exception ex)
{
    var message = ...
    throw new InvalidOperationException(message, ex.InnerException);
}

This is clearly an attempt to add context when an exception happens - but it does so by throwing away some of the best available diagnostics. I modified it to avoid throwing away the intermediate level of the exception stack.

Sigh.

Comments

blog comments powered by Disqus
Next Post
Visual Studio 2012 RC Woes  17 Jun 2012
Prior Post
WordTutor update  26 May 2012
Related Posts
Error Methods  25 Nov 2017
Pass implementations, not representations  14 Oct 2017
Avoiding the Singleton Pattern  22 Jul 2017
Implementing the Singleton Pattern  15 Jul 2017
Static Analysis tools for the Win  15 Apr 2017
Exception Logging  19 Jan 2016
On the Merits of Simple Code  28 Nov 2015
Semantic Types  27 Sep 2015
Command Line Processing  21 Sep 2014
Easy String Conversion  24 Aug 2014
More smart-code posts »
Related Pages
June 2012 archive