Promises.all does not hit catch() block when one promise fails?

I'm trying to run a function when two compilation steps are complete, but the success callback keeps getting called even one fails. Here's the code:

function compile(tplStr) {
  return new Promise(function(resolve,reject) {
    // compile template here
    var tpl = new function(){};

function parse(json) {
  return new Promise(function(resolve,reject) {
    try {
      var obj = JSON.parse(json);
    } catch(err) {
      console.log('JSON parse failed');

var i = 0;

function bothReady() {

function oneFailed(err) {
  console.log('oneFailed hit');

var compileProm = compile($('#a').val());
var parseProm = parse($('#b').val());


$('#a').on('input', function() {

$('#b').on('input', function() {

code pen

When I create a syntax error in the JSON portion it logs "JSON parse failed" but does not log "oneFailed hit" like I'd expect. Why not? Shouldn't the .catch block be ran if any of the promises are rejected?


Your code doesn't work correctly when something is typed inside of #b because instead of passing an iterable to Promise.All 2 parameters are passed instead.

The result is that while both promises run, only the result of the first one is taken into account by the continuation of all.

The code read


Instead of


PS: The 2 other calls are correct it explain why the problem seem to happen only when editing the JSON.

Need Your Help

Hosts file missing on Mac OS X - Xcode Failing to compile code

xcode osx file cat hosts

I've tried to run my first objective-c code in Xcode... Compilation process was successfully, however an error returns " invalid host string: 'localhost' ".

how to create a thread to refresh data in 3 second interval


I need a thread (it does httppost ,and parse the answer xml and refresh listview to set the changes from parsed xml) in 3 sec interval

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.