c# - 在 Invoked 方法中抛出异常时,特定异常捕获块不起作用
问题描述
在下面的代码中,我有一个 System.UnauthorizedAccessException 类异常的 catch 块。
try
{
var type = message.Form.GetObjTypeOf(typeof(BaseEntity));
MethodInfo updateFormStatusMethod = typeof(IFormService).GetMethod("UpdateFormStatus");
MethodInfo generic = updateFormStatusMethod.MakeGenericMethod(type);
var result = (bool)generic.Invoke(performanceformService, new object[] { message });
// I throw new System.UnauthorizedAccessException() inside 'UpdateFormStatus' method
}
catch (System.UnauthorizedAccessException)
{
// I'm waiting to get 'UnauthorizedAccessException' here
}
catch (System.Exception ex)
{
//But I get it here
}
我正在等待在特定的 catch 块中获得“UnauthorizedAccessException”,但我在一般的 catch 块中得到它。
解决方案
推荐阅读
- swift - 如何处理 Process.run 抛出的异常
- javascript - 使用 JsRender 按列创建 GRID,使用数学辅助函数
- vba - MS Access 数据库关闭,忽略表单关闭取消 true
- laravel - Laravel:无需猜测即可诊断“未捕获的反射:类日志不存在”的方法?
- sql-server - 如何解决 Pandas 中“远程过程调用协议流中的传入表格数据流不正确”的错误
- reactjs - 查找反应,将我的 getSituations 中的信息带到列表组合框
- python - 无法 pip 安装 Tensorflow 'msvcp140_1.dll' 缺失
- shell - 在 zsh 中嵌套 ${name:offset:length} 和 $()
- c++ - 即使函数已经存在,C++ 未定义的函数引用错误
- java - admob SettingEnabled false