I am developing an application for Windows 8 Metro using Javascript (WinJS).
Let’s say I have the following code:
Windows.Storage.ApplicationData.current.localFolder.createFileAsync("test.dat", Windows.Storage.CreationCollisionOption.replaceExisting)
.done(
/* write some data to the file here */)
var x = null;
x.prop = 1;
It is obvious that the previous code will crash on the line x.prop = 1. What happens to the createFileAsync Promise?
Doing a simple debug test yields the fact that the Promise will be finished even though the app crashes, but can I be certain that that will always be the case, and that the file will be created and written?
Thanks.
I don’t think you can be certain that the Promise will complete if the app crashes. If the operation that returns the Promise completes quickly enough, it might. But if you’re looking for a guarantee, I don’t think you’ll get that.
I would recommend coding defensively, so that if the file is not created, you can create it the next time your app runs.
Of course, most importantly, you should be doing proper exception handling to ensure that the app does not crash because of a simple exception.
For more info on developing Windows Store apps, check out Generation App.