/var/log

Tag: Promise

Catch errors in Promise

When using the static resolve() Promise method, you often see code like this: Promise.resolve(func()).then(function(result) { console.log("Ok for: " + result); }).catch(function(error) { console.log("Error: " + error); }); console.log("Some code running after Promise.resolve..."); Everything is ok when the func() function has no errors: function func() { return "OK!"; } Output: Some code running after Promise.resolve... Ok […]