【发布时间】:2018-06-19 22:42:27
【问题描述】:
我已经能够使用以下代码在UWP C++ 应用程序中成功打开和读取文件:
FileOpenPicker^ openPicker = ref new FileOpenPicker();
openPicker->SuggestedStartLocation= PickerLocationId::DocumentsLibrary;
openPicker->FileTypeFilter->Append(".txt");
create_task(openPicker->PickSingleFileAsync()).then([this](StorageFile^ file)
{
if (file)
{
create_task(FileIO::ReadTextAsync(file)).then([this](Platform::String^ text) {
MessageDialog^ msg = ref new MessageDialog(text);
msg->ShowAsync();
});
}
else
{
MessageDialog^ msg = ref new MessageDialog("Operation cancelled.");
msg->ShowAsync();
}
});
但是,如果文件内容是非文本的,例如二进制,应用程序崩溃。如何实现错误处理?我尝试使用try...catch 失败。
【问题讨论】:
标签: file error-handling uwp c++-cx