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 :: js string to array 
Javascript :: hover effect in material ui 
Javascript :: react js onclick call two functions 
Javascript :: convert number to word js crore/lakh format 
Javascript :: refresh a page in the browser node js 
Javascript :: express response setTimeout 
Javascript :: jquery set input value 
Javascript :: jquery fadein display new page 
Javascript :: sh: /Users/ahmedqadri/Desktop/Projects/stockNotesAPP-frontend/node_modules/.bin/react-scripts: Permission denied 
Javascript :: picker change event react native 
Javascript :: What is the Difference between Undefined, undeclared, Null 
Javascript :: datatables filter with math functions 
Javascript :: time taken for a function javascript 
Javascript :: react fetch custom hook 
Javascript :: strapi change user password 
Javascript :: react how to update state array 
Javascript :: layout nextjs 
Javascript :: access to xmlhttprequest has been blocked by cors policy react 
Javascript :: downgrade node version windows using npm 
Javascript :: how to add important tag js 
Javascript :: datatable order number 
Javascript :: append row javascript 
Javascript :: how to find largest number in array in javascript 
Javascript :: [PrivateRoute] is not a <Route component. All component children of <Routes must be a <Route or <React.Fragment 
Javascript :: how to scroll to an element javascript react 
Javascript :: javascript get parent by tag 
Javascript :: node.js express post query string 
Javascript :: nodejs reverse string 
Javascript :: nodejs path 
Javascript :: math ceil 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =