C# MethodInfo调用方法的异常处理

C# MethodInfo调用方法的异常处理,c#,exception-handling,C#,Exception Handling,我有一个关于异常处理程序的常规重试,我希望它在一定的时间内重复一个函数,下面是它的代码 public static void Retry(this MethodInfo methodInfo, object[] parametrsList, short after = 0, short? retry = 1) { if (retry < 0) return; try { short waitingPeriodMs = after*10

我有一个关于异常处理程序的常规重试,我希望它在一定的时间内重复一个函数,下面是它的代码

public static void Retry(this MethodInfo methodInfo, object[] parametrsList, short after = 0, short? retry = 1)
{
    if (retry < 0)
        return;
    try
    {
        short waitingPeriodMs = after*1000;
        Thread.Sleep(waitingPeriodMs);
        Type classObjType = methodInfo.ReflectedType;
        object classObj = Activator.CreateInstance(classObjType);
        methodInfo.Invoke(classObj, parametrsList);
    }
    catch (TargetInvocationException ex)
    {
        Debug.WriteLine("Exception Caught");
        methodInfo.Retry(parametrsList, after, --retry);
    }
    catch (Exception ex)
    {
        Debug.WriteLine("Exception Caught");
        methodInfo.Retry(parametrsList, after, --retry);
    }
}

我真的不明白异常如何绕过这些捕获块。是所有异常还是某些特定异常都会发生这种情况?调用的方法是否在单独的线程中运行?@KMoussa是,它是在单独的线程中调用的thread@Scarnet这可能就是为什么不执行catch块的原因,请参阅@KMoussa,我的情况并非如此。重试方法本身是在与主线程分离的线程中执行的,但它调用的方法从未在单独的线程中开始执行
[TestClass]
public class ExceptionTest
{
    [TestMethod]
    public void TestExceptionRetry()
    {
        Action act = () => { throw new Exception(); };
        act.Method.Retry(new object[0]);
    }
}