我收到unreachable code
警告catch catch并且我无法调试。请建议我如何纠正这种错误:在C#.Net中检测到无法访问的代码.net
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'方法调用能够工作? (你应该学习.NET命名约定,顺便说一句)。 –
正如错误信息中所述,'Global.writeLog(“”+ e.ToString());'部分是不可访问的,因为你之前没有抛出异常处理它。 –