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
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
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
When are you done?  18 Apr 2022
Fixing GitHub Authentication  28 Nov 2021
Archives
June 2012
2012