gpt4 book ai didi

c# - 在 C#.Net 中检测到无法访问的代码

转载 作者:太空宇宙 更新时间:2023-11-03 18:58:58 26 4
gpt4 key购买 nike

我在 catch block 中收到 unreachable code 警告,我无法调试。请建议我如何纠正该错误:

private void HandleDevelopmentServer()
{
string sErrMsg = "";
try
{
QuasarInterfaces.ISecurity oSecurity = null;
Global.CreateSecurityComponent(ref oSecurity);
System.Data.DataSet oDS;
DataTable dtDBSettings = new DataTable();
string sDBString = System.Configuration.ConfigurationSettings.AppSettings["Environment"];
Global.ReadDBConfig(sDBString, ref dtDBSettings);
oSecurity.FetchAllUsers(out oDS, out sErrMsg, dtDBSettings)

if (sErrMsg.Length > 0)
throw new Exception(sErrMsg);

if ((oDS != null) && (oDS.Tables.Count != 0))
{
DropDownList1.DataSource = oDS;
DropDownList1.DataBind();
}
}
catch (Exception e)
{
throw new Exception("HandleDevelopmentServer function failed;" + e.Message);
Global.writeLog("" + e.ToString());
}
}

最佳答案

这条线永远不会发生:

Global.writeLog("" + e.ToString()); 

你在它上面抛出一个异常,这意味着这个方法将在那个点退出到调用堆栈中的前一个

只要将两者切换就可以了。

catch (Exception e)
{
Global.writeLog("" + e.ToString());
throw new Exception("HandleDevelopmentServer function failed;" + e.Message);
}

您还可以删除 ""+

关于c# - 在 C#.Net 中检测到无法访问的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39035577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com