gpt4 book ai didi

error-handling - 防止WinJS应用程序在文件调用失败时崩溃

转载 作者:行者123 更新时间:2023-12-03 08:54:05 25 4
gpt4 key购买 nike

我目前正在平板电脑的Windows 8.1应用程序上工作。我想从用户驱动器上单击单击一个xls文件。问题是,到目前为止,我的代码无法防止在找不到文件的情况下App崩溃。我需要某种错误处理,可以简单地防止这种情况发生并发送警报或其他内容。

这是我到目前为止所拥有的

        var me = this;
var fileName = "ReportCall.xls";
var localFolder = Windows.Storage.ApplicationData.current.localFolder;
var reportFile = localFolder.getFileAsync("Attachments\\Reports\\fileName");
var file = local.Folder.getFileAsync(fileName);

reportFile.done(function(file) {
Windows.System.Launcher.launchFileAsync(file).done(
function (success) {
if (success) {
// DO NOTHING
} else {
//Alert. File not found!
}
});
});

有任何想法吗?

干杯

最佳答案

设法通过以下代码解决了问题

var me = this;
var fileName = "ReportCall.xls";
var localFolder = Windows.Storage.ApplicationData.current.localFolder;
var file = localFolder.getFileAsync(fileName):

localFolder.getFileAsync("Attachments\\Reports + fileName").then(function)(file {
},function(e) {
alert("file cannot be found");
});

关于error-handling - 防止WinJS应用程序在文件调用失败时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31857749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com