【发布时间】:2010-08-30 08:54:54
【问题描述】:
我有这个调用 MethodInfo 的代码:
try
{
registrator.Method.Invoke(instance, parameters);
}
catch{
registrator.FailureType = RegistratorFailureType.ExceptionInRegistrator;
//registrator.Exception = e;
}
注册器只是一个 MethodInfo 包装器,Method 属性是 MethodInfo 对象本身。 parameters 和 object[] 和 instance 是 Method 的声明类型的正确实例(使用 Activator.Create 创建)。
方法看起来像这样(我正在测试异常捕获):
class Test : Plugin, ITest
{
public void Register(IWindow window)
{
throw new Exception("Hooah");
}
}
问题是:异常永远不会被捕获,并且 Visual Studio 的未捕获异常气泡会弹出。
这是在带有 .NET 4.0 的 VS 2010 中
【问题讨论】:
-
您可以,也许,喜欢,也许,告诉我们例外是什么?
-
你能写出一个小而完整的例子程序来展示这个问题吗?
-
哪种类型的注册器是实例?可能问题出在 catch 子句中(FailureType 或 registrator 为 null)
-
@Timwi:你的意思是未捕获的异常?这正是 Register 方法中抛出的内容:带有消息“Hooah”的异常类型对象
标签: c# .net reflection