单声道框架反射调用抛出 OverFlowException

问题描述

在dotnet框架或mono框架中,通过反射调用方法调用过程中的异常会被TargetInvocationException包裹起来。但是我发现OverFlowException在mono中表现出不同的行为,它没有任何包装直接抛出,这是mono框架的错误吗?

示例代码

public class Demo
{
   private void test()
   {
      throw new OverflowException();
   }
}

class Program
{
   static void Main(string[] args)
   {
       Demo demo = new Demo();
       MethodInfo method = typeof(Demo).getmethod("Test",BindingFlags.Instance | BindingFlags.NonPublick);
       
       try
       {
          method.Invoke(demo,new object[0]);
       }
       catch(OverflowException)
       {
          //for mono framework,throws OverflowException
       }
       cathc(TargetInvocationException)
       {
          //for dotnet framework,throws TargetInvocationException
       }
   }
}

同样的代码,在mono和dotnet中执行不同,只有OverflowException才显示出这种差异,谁能解释一下原因?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)