How to show exceptions for unhandled errors in Q promises

I noticed that if the callback .then()fails due to some error (for example, operations with the undefined variable) and does not exist .catch(), the error is ignored.

This is rather inconvenient during development.

For example, this code will exit without any errors:

var Q = require('q');

var promise = Q('something');
promise
.then(function() {
  buggyCode();
})

A possible fix is ​​to manually add an error handler like this, but there is nothing built in for this?

.catch(function(error) {
  console.error(error.stack);
})
+4
source share
2 answers

Apparently, this restriction is the Q .

, .done(), , , .

, , , , prom-consumer .done().

+3

Q.

then() catch(), - Q. then() , ; "catch()" , :

someFn()
  .then(doStuff)
  .catch(handleError)

- , done() , , :

try {
    someFnThatGeneratesAnError().done()
} catch(e) { ... }

, catch() done(), , , Q onerror, , done() , , , .

, catch(), onerror, , then() vs done().

+1

All Articles