[英]Exception was unhandled - rethrow exception
我嘗試重新拋出異常,但它不起作用。 我在 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;
}
}
此方法屬於 class 庫,我從控制台應用程序調用它。 請幫我。
謝謝。
它按預期工作。
您捕獲,然后重新拋出異常 - 您現在沒有處理重新拋出的異常。 這就是您收到錯誤的原因。
捕獲,進行一些處理,然后拋出異常的目的是使它可以被堆棧中代碼上方的某個 catch 語句捕獲。 如果在任何地方都沒有捕獲到異常,它將 go 上升到 CLR 級別並停止進程。
如果你想捕獲異常,處理它,然后繼續,這很簡單:只是不要把它扔回 catch 語句中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.