如何处理异步函数中的异常UWP应用程序getFileFrompathAsync(path);
How to handle exception in async function UWP App GetFileFromPathAsync(path);
此代码在投掷时不会捕获AccessDeniedException。
为什么?
没有任何例外处理程序会抓住它。我已经完全遵循了文档。
auto fileOp = StorageFile::GetFileFromPathAsync(filePath);
auto fileTask = create_task(fileOp);
auto c1 = fileTask.then([](StorageFile^ file) {
//...
}).then([](task<StorageFile^> t) {
try {
auto ident = t.get();
}
catch (const std::exception &e) {
auto msg = ref new MessageDialog("File not found.");
}
catch (AccessDeniedException^ e) {
auto msg = ref new MessageDialog("Access denied.");
}
catch (Exception^ e) {
auto msg = ref new MessageDialog("Unknown errer.");
}
});
要处理GetFileFromPathAsync
方法中抛出的异常,您可以尝试以下代码:
auto fileOp = StorageFile::GetFileFromPathAsync(filePath);
auto fileTask = create_task(fileOp);
auto c1 = fileTask.then([](task<StorageFile^> t) {
try
{
StorageFile^ file = t.get();
///...
}
catch (AccessDeniedException^)
{
auto msg = ref new MessageDialog("Access denied.");
create_task(msg->ShowAsync());
}
catch (Exception^ e) {
auto msg = ref new MessageDialog(e->Message);
create_task(msg->ShowAsync());
}
});
相关文章:
- 如何在 Win32 C++控制台应用程序中调用 UWP 类库
- 确定C++应用程序是否作为具有旧版支持的 UWP 应用运行
- 我可以用C++/WinRT编写一个DLL,供windows桌面应用程序(而不是UWP)或Unity插件使用吗
- 如何处理异步函数中的异常UWP应用程序getFileFrompathAsync(path);
- 将UWP应用程序的简单INT发送到另一个程序
- 在 UWP C++应用程序中生成 JVM 时崩溃
- 如果我在 Xbox UWP 应用程序上收到激活错误并且错误消息中没有任何有用的内容,该怎么办
- 通过UWP应用程序定位Windows 10,通过OpenNi 2访问构造传感器
- C DLL通过C#UWP应用程序中的Win运行时组件适用于ARM,但对于X86/X64不适用于
- 相机枚举的选项和UWP应用程序的HAL(WPF/C CLI DLL)
- 如何从Qt应用程序访问UWP API
- 如何从功能(C UWP应用程序)中修改按钮内容
- 在 UWP 应用程序中,future.wait() 在尝试同步来自异步方法的响应时继续等待
- 从服务打开 UWP 应用程序
- UWP 应用程序拒绝接收 P2P 服务器部件中的数据
- 在UWP中获取fopen()的应用程序路径
- Windows 10 UWP桌面桥应用程序(C ):调试构建中的VCLIBS依赖关系
- 从 UWP 应用程序中提取图标
- 在UWP应用程序中加载并显示DDS(DXT1)文件
- 覆盖Windows 10通用应用程序UWP上的关闭框