Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

.catch() in promise will aslo return a promise

var p1 = new Promise(function(resolve, reject) {
  resolve('Success');
});

p1.then(function(value) {
  console.log(value); // "Success!"
  throw new Error('oh, no!');
}).catch(function(e) {
  console.error(e.message); // "oh, no!"
}).then(function(){
  console.log('after a catch the chain is restored');
}, function () {
  console.log('Not fired due to the catch');
});

// The following behaves the same as above
p1.then(function(value) {
  console.log(value); // "Success!"
  return Promise.reject('oh, no!');
}).catch(function(e) {
  console.error(e); // "oh, no!"
}).then(function(){
  console.log('after a catch the chain is restored');
}, function () {
  console.log('Not fired due to the catch');
});
Comment

.catch() in promise will aslo return a promise

// Throwing an error will call the catch method most of the time
var p1 = new Promise(function(resolve, reject) {
  throw new Error('Uh-oh!');
});

p1.catch(function(e) {
  console.error(e); // "Uh-oh!"
});

// Errors thrown inside asynchronous functions will act like uncaught errors
var p2 = new Promise(function(resolve, reject) {
  setTimeout(function() {
    throw new Error('Uncaught Exception!');
  }, 1000);
});

p2.catch(function(e) {
  console.error(e); // This is never called
});

// Errors thrown after resolve is called will be silenced
var p3 = new Promise(function(resolve, reject) {
  resolve();
  throw new Error('Silenced Exception!');
});

p3.catch(function(e) {
   console.error(e); // This is never called
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to put value in arrar 
Javascript :: javascript channel flutter inappWebview 
Javascript :: check if element is displayed 
Javascript :: html5 web component 
Javascript :: java script discord timer 
Javascript :: how to say "and not" in javascript 
Javascript :: call function on scroll down javascript 
Javascript :: nestjs multer file upload delay 
Javascript :: JS equal sibling btns height 
Javascript :: how to make your own version of filter method 
Javascript :: object with key as individual choice and values as the second choice 
Javascript :: Cannot coerce `dirty` to string because boolean [1] should not be coerced. 
Javascript :: combine 2 data in column 
Javascript :: get last day of month js 
Javascript :: regex placa de carro 
Javascript :: Get JSON Key In Array Alternative Syntax 
Javascript :: JavaScript combining rows of multiple datasets 
Javascript :: javascript convert string to number with 2 decimal places 
Javascript :: js change img ssrc 
Javascript :: remove nth character from string javascript 
Javascript :: Backbone Models In Collection Is Added Here 
Javascript :: Simplest Template Example 
Javascript :: convert snake case to camelcase javascript recursive 
Javascript :: moment format time 
Javascript :: nextjs youtube embed 
Javascript :: javascript custom table 
Javascript :: Change slick slider slides from another component 
Javascript :: double exclamation mark javascript 
Javascript :: forming a magic sqare hackerank in javascript 
Javascript :: set timeout with no name 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =