异常未处理 - 重新抛出异常
我尝试重新抛出异常,但它不起作用。 我在 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;
}
}
该方法属于类库,我从控制台应用程序调用它。 请帮我。
谢谢。
I try to rethrow an exception, but it's not working.
I get 'Exception was unhandled' error in 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;
}
}
This method belong to a class library, and i call it from a console application.
Please, help me.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

它正在按预期工作。
您捕获并重新抛出异常 - 您现在没有处理重新抛出的异常。这就是您收到错误的原因。
It is working as expected.
You catch, then rethrow the exception - you are now not handling the rethrown exception. That's why you are getting the error.