Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

promise catch

//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!"
});
Comment

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);
Comment

PREVIOUS NEXT
Code Example
Javascript :: react show view based on role permission 
Javascript :: leaflet geojson style stroke width 
Javascript :: rotate13 text in javascript 
Javascript :: react hook form with controlled input 
Javascript :: start nodemon under wsl2 
Javascript :: onselect in zebra datepicker 
Javascript :: delegate click in jquery 
Javascript :: json schema e.g. 
Javascript :: Remove an item from the beginning of an Array 
Javascript :: javascript add item in list 
Javascript :: mongoose encrypt database using mongoose encrypt package 
Javascript :: Highlight current nav link in react 
Javascript :: react axios POST using async await method with super constructor parent class 
Javascript :: javascript append classname 
Javascript :: js shallow copy 
Javascript :: * ws in ./node_modules/puppeteer/lib/WebSocketTransport.js 
Javascript :: ionic vue use .env 
Javascript :: can we use setstate inside build 
Javascript :: node import json 
Javascript :: active class always appear in navlink 
Javascript :: react native fontsize not affected by phone settings 
Javascript :: call dynamic var name javascript 
Javascript :: javascript event listener get id of clicked items 
Javascript :: how to make html with jquery 
Javascript :: vue js data property in component must be a function 
Javascript :: Angular p-dialog 
Javascript :: delete embeds field discord.js 
Javascript :: this js 
Javascript :: blob to pdf javascript 
Javascript :: stale element reference: element is not attached to the page document 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =