处理错误的正确方法是什么?我有如下代码,处理我在 MSDN 上找到的所有错误代码,但有时我收到错误“未知”。
HRESULT hr = pwb->Navigate2(&URL, &Flag, &TargetFrameName, &PostData, &Headers);
if(FAILED(hr))
{
std::string message("Navigate2 failed with reason: ");
switch(hr)
{
// The operation was successful.
case S_OK:
message.append("S_OK");
break;
// One or more parameters are invalid.
case E_INVALIDARG:
message.append("E_INVALIDARG");
break;
// Out of memory.
case E_OUTOFMEMORY:
message.append("E_OUTOFMEMORY");
break;
// The operation failed.
case E_FAIL:
message.append("E_FAIL");
break;
case E_ACCESSDENIED:
message.append("E_ACCESSDENIED");
break;
case E_POINTER:
message.append("E_POINTER");
break;
case E_UNEXPECTED:
message.append("E_UNEXPECTED");
break;
default:
message.append("Unknown");
}
}