c# - 异常未处理 - 重新抛出异常

标签 c# .net exception console-application class-library

我尝试重新抛出异常,但它不起作用。 我在 visual studio 中收到“异常未处理”错误。

public KeyValueConfigurationCollection getMyAppSetting()
{
  Configuration config;
  ConfigurationFileMap configFile;
  try
  {
    configFile = new ConfigurationFileMap(ConfigurationManager.OpenMachineConfiguration().FilePath);
    config = ConfigurationManager.OpenMappedMachineConfiguration(configFile);
    AppSettingsSection MyAppSettingSection = (AppSettingsSection)config.GetSection("xxx/appSettings");
    MyAppSettingSection.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToRoamingUser;
    return MyAppSettingSection.Settings;
  }
  catch (Exception ex)
  {
    logger.Fatal("...");
    throw;
  }
}

此方法属于类库,我从控制台应用程序调用它。 请帮我。

谢谢。

最佳答案

它按预期工作。

您捕获异常,然后重新抛出 - 您现在没有处理重新抛出的异常。这就是您收到错误的原因。

关于c# - 异常未处理 - 重新抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6778268/

相关文章:

c# - 如何从方法中返回多种可能性中的一种

c# - JSON 类型字符串的正则表达式

c# - Serilog 中的异常解构

c# - 如何设计与不可测试函数绑定(bind)的可测试代码

c# - List 对象的 !Contains() 不起作用

java - AspectJ 和 PostSharp 之间的功能差异是什么?

.net - 构造函数调用其他构造函数: any performance issues?

c# - 在 Debug模式下观察变量时出现 FileNotFoundException

Symfony 4 - 控制台异常事件监听器

c# - 如何在 C# Windows 窗体中使用 LAST_INSERT_ID()?