-
Notifications
You must be signed in to change notification settings - Fork 26
Exceptions swallowed by promises #17
Comments
Thanks @hgwood for reporting this. I will investigate this and get back to you. |
@hgwood , I would go with .then().done() approach as given below. I verified that this lets you catch the errors and close the uwp. var uwp = require('uwp');
uwp.projectNamespace("Windows");
Windows.Storage.KnownFolders.documentsLibrary.createFileAsync(
"sample.dat", Windows.Storage.CreationCollisionOption.replaceExisting)
.then(
function (file) {
undefinedFunc();
},
function (error) {
undefinedFunc();
}
).done(
function (result) {
},
function (error) {
console.log('handle all the errors');
uwp.close(); // close uwp
}
); |
That's a nice work-around thanks, but wouldn't you say the original problem is a bug? Shouldn't |
Sorry if I add clutter to the conversation but it surprise me to see the Following the links from MSDN leads to a deprecated test suit for Promises/A. AFAIK the list is:
Is the exact behavior of |
Off the top of my head, I can only think of the following similar cases for JS Promises: // Thenable throws before callback
// Promise rejects
var thenable = { then: function(resolve) {
throw new TypeError("Throwing");
resolve("Resolving");
}};
var p1 = Promise.resolve(thenable);
p1.then(function(v) {
throw new Error("Should not be called"); // not called
}, function(e) {
console.log(e); // TypeError: Throwing
});
// Thenable throws after callback
// Promise resolves
var thenable = { then: function(resolve) {
resolve("Resolving");
throw new TypeError("Throwing");
}};
var p2 = Promise.resolve(thenable);
p2.then(function(v) {
console.log(v); // "Resolving"
}, function(e) {
throw new Error("Should not be called"); // not called
}); |
@dotnetCarpenter |
Reprising your sample and introducing an obvious mistake shows that errors don't seem to escape promise handlers:
Running this shows no error, it just runs eternally because
uwp.close()
is never called. It makes it hard to detect errors, especially programming ones.I read about
WinJS.promise.onerror
, but I'm not sure how it relates to the uwp module. Any pointers?The text was updated successfully, but these errors were encountered: