promise catch javascript
// errors that occur in asynchronous code inside promises cannot be caught with regular try/catch
// you need to pass the error handler into `.catch()`
fetchUserData(userId).then(console.log).catch(handleError);//create a Promise
var p1 = new Promise(function(resolve, reject) {
resolve("Success");
});
//Execute the body of the promise which call resolve
//So it execute then, inside then there's a throw
//that get capture by catch
p1.then(function(value) {
console.log(value); // "Success!"
throw "oh, no!";
}).catch(function(e) {
console.log(e); // "oh, no!"
});
Also in JavaScript:
- javascript get multiple elements by id
- app.use(validator()) is not a function
- unterminated substitute in regular expression
- how to move up in terminal
- iterate over array javascript
- multi language website angular 6
- js promise examples
- install javascript kali linux
- js data object length
- js join two arrays
- javascript void(0) href
- setinterval javascript
- js string
- two object combine together javascript
- string.contains javascript
- how to generate random text in vue js
- destructure array javascript
- javascript foreach key value
- jquery delete grand parent of clicked element
- how to get all elements with same class in javascript
- jquery validator Url
- javascript picture delete after time
- how to pass dynamic string in string javascript
- js root url