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
Avoid hardcoded wait times  26 May 2018
Guaranteed Progression  19 May 2018
Prefer declarative method names  03 Feb 2018
Using Premeditation  27 Jan 2018
With Relocation  20 Jan 2018
Using Consolidation  13 Jan 2018
Using Semantic Types  06 Jan 2018
Using Extension Methods  30 Dec 2017
Error Methods  25 Nov 2017
Pass implementations, not representations  14 Oct 2017
More smart-code posts »
Archives
June 2012
2012