我收到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());'部分是不可訪問的,因爲你之前沒有拋出異常處理它。 –