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