我打算使用以下代码下载文件。它在WIFI可用时工作;但当没有Wifi时,我希望能抓住
previousTask.get()
不幸地
catch
在我的代码中似乎没有捕捉到异常。例外情况是
HRESULT:0x80072F30 The text associated with this error code could not be found.
顺便说一句我是不是错过了一些不可计算的例外?
auto httpClient = ref new HttpClient();
auto get_operation = httpClient->GetAsync(ref new Uri(url), HttpCompletionOption::ResponseContentRead);
get_operation->Progress = progressHandler;
auto response = create_task(get_operation).then([](task<HttpResponseMessage^> previousTask)
{
try
{
return previousTask.get();
}
catch (Exception^ ex)
{
// Some how this does not catch
OutputDebugString(("Exception: " + ex->Message)->Data());
return (HttpResponseMessage^)nullptr;
}
}).get();
// At this point, I expect either a fully read response or response=nullptr
// Code to write to file is omitted
编辑
:~~我测试了微软官方的
HttpClient sample
其显然使用类似的代码。显然,当没有网络连接时,该应用程序也会发生同样的崩溃。这种情况证实了缺陷存在于操作系统端,对此我们无能为力~~
编辑
:事实证明,我认为该异常没有被捕获,因为Visual Studio会弹出一个对话框,我认为这意味着实际上该异常会导致应用程序崩溃,即当它未通过VS启动时;按对话框上的[继续]按钮进入
接住
条款从“开始”菜单启动应用程序没有问题。