【发布时间】:2018-03-23 14:08:47
【问题描述】:
所以我有以下代码:
StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder;
concurrency::create_task(storageFolder->GetFileAsync(txtfile)).then([](StorageFile^ sampleFile)
{
concurrency::create_task(FileIO::AppendTextAsync(sampleFile, New_Program_Data)).then([]() {
});
});
我用它来打开一个文本文件并将一些数据附加到末尾。如果文件丢失、损坏或无法打开,如何添加异常处理?
我在任务内外尝试了各种 try and catch 语句,但在调试时似乎没有任何效果。应用程序将中断并显示未处理的异常错误。
【问题讨论】:
-
你需要使用
task<StorageFile^>s作为countinuation函数的参数来获取异常,如果你使用StorageFile^你将无法获取异常。见msdn.microsoft.com/en-us/library/dd997692.aspx 和stackoverflow.com/a/15123425/8918119
标签: exception concurrency exception-handling uwp c++-cli