public static ReturnedCommands returnedCommands;
... 및 null 참조 예외는 값 "3"을 반환 발생 :
public bool PendingCommandsExecute_QUERY()
{
int i = 0;
try
{
i = 1;
cmdResults b = cmdResults.cmdFail;
bool retVal = false;
string command = "QUERY";
if (returnedCommands.key != command)
return false;
HashResultsAdd(command, "Started");
i = 2;
HashStatus.Clear();
string sNum = PendingCommands.SiteFetchSiteNumber;
i = 3; // <-- last one reached (debug int displayed in NRE)
string s = string.Empty;
if (returnedCommands.command != null)
{
s = command + "|" + sNum.Trim() + "|t_inv|SELECT|" + returnedCommands.command;
}
i = 4;
HashStatusAdd(command, s);
. . .
}
catch(Exception ex)
{
MessageBox.Show(ex.Message + " reached debug int " + i.ToString());
}
return true;
} // PendingCommandsExecute_QUERY
을
NRE가 발생하면 "예외 : 널 참조 예외가 디버그 int 3에 도달했습니다"가 표시됩니다. returnCommands.command를 참조하면서 imploding해야합니다. 그러나 returnedCommands.command는 단순히 문자열이므로 어떻게 될까요? 먼저 null이 아닌지 확인합니다 ("if (returnedCommands.command! = null)"행). 테스트가 문제가되지 않도록 안전해야합니다. 그 테스트를 통과한다면 그것은 단지 문자열 연결 연산 일 뿐이므로 어떻게 NRE를 일으킬 수 있습니까?
오컬트 int를 사용하는 대신 디버거를 사용하여 영향을받은 라인을 단계별로 실행할 수 있습니까? – Nolonar
'sNum'을 확인 했습니까? 아마도 null이 될 것입니다. – Jason
그건 그렇고 :'ex.ToString()'은'ex.Message'보다 훨씬 많은 정보를 얻습니다. – Nolonar