1
我正在使用Windows 8應用程序(C++)。我使用了Windows 8樣本集合中的httpclient類。如何捕捉異常[C++/CX]
inline void CheckHResult(HRESULT hResult)
{
if (hResult == E_ABORT)
{
concurrency::cancel_current_task();
}
else if (FAILED(hResult))
{
throw Platform::Exception::CreateException(hResult);
}
}
當應用程序未連接到互聯網時,此函數會引發異常。我試圖在下面的lambda中捕獲異常。
return completionTask.then([this, stringCallback](tuple<HRESULT, wstring> resultTuple)
{
try
{
CheckHResult(std::get<0>(resultTuple));
}
catch(Exception^ ex)
{
}
return std::get<1>(resultTuple);
});
但它仍然顯示未處理的異常:
First-chance exception at 0x77194B32 in Sample.exe: Microsoft C++ exception: Platform::COMException^at memory location 0x08C7EDF4. HRESULT:0x800C0005
If there is a handler for this exception, the program may be safely continued.
有什麼我做錯了嗎?
非常感謝您的幫助。學習像你這樣的知識淵博的人是很好的:) – 2013-04-07 12:09:03