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
Old blog posts, restored  26 Oct 2025
Better Table Tests in Go  21 Oct 2025
Error assertions  26 Apr 2025
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Archives
June 2012
2012