为什么我可以在C#中编写一个通用的catch语句,什么都不做?

Ant*_*ean 10 c# generics try-catch circuit-breaker

可能重复:
为什么我不能在C#中捕获一般异常?

我最近一直在审查和编写Circuit Breaker代码.编译以下方法,但永远不会输入catch块.我有很多解决方法,这不是获得正确行为(过滤异常)的唯一方法,但我很好奇为什么这个编译并且不起作用!

public void AttemptCall<TException>(Action action) 
    where TException : Exception
{
    try
    {
        action();
    }
    catch(TException e)  // This block is never entered!
    {
         state.ActUponException(e);
         throw;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是一个应该进入前一个方法的catch块的测试.

[TestMethod]
public void Throw_an_exception()
{
    circuitBreaker.AttemptCall<Exception>(() => throw new Exception());
    // test the circuit breaker's state
}
Run Code Online (Sandbox Code Playgroud)