S
S
Svyatoslav Khusamov2016-07-20 21:54:45
Node.js
Svyatoslav Khusamov, 2016-07-20 21:54:45

How to add a delayed error handler to a Promise?

If you write like this, then the error is not caught:

let bbb = Promise.resolve();
  
  bbb.then(none => {
    throw "ошибк2";
  })
  
  bbb.catch(err => {
    console.log(err)
  });

And if you write like this, then the error appears in the console:
Promise.resolve()
  
  .then(none => {
    throw "ошибк2";
  })
  
  .catch(err => {
    console.log(err)
  });

I need to ask catch a little later, but it turns out that I can't do it???
Here is node.js version 6, Promise is a built-in class.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sugadu, 2016-07-20
@khusamov

but like this?

let bbb = Promise.resolve();
  
  var aaa = bbb.then(none => {
    throw "ошибк2";
  })
  
  aaa.catch(err => {
    console.log(err)
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question