title: How to return from a Promise's catch/then block?
body: <p>There are many tutorials on how to use "then" and "catch" while programming with JavaScript Promise. However, all these tutorials seem to miss an important point: returning from a then/catch block to break the Promise chain. Let's start with some synchronous code to illustrate this problem:</p>
  
  <pre><code>try {
    someFunction();
  } catch (err) {
    if (!(err instanceof MyCustomError))
      return -1;
  }
  someOtherFunction();
  </code></pre>
  
  <p>In essence, I am testing a caught error and if it's not the error I expect I will return to the caller otherwise the program continues. However, this logic will not work with Promise:</p>
  
  <pre><code>Promise.resolve(someFunction).then(function() {
    console.log('someFunction should throw error');
    return -2;
  }).catch(function(err) {
     if (err instanceof MyCustomError) {
       return -1;
     }
  }).then(someOtherFunction);
  </code></pre>
  
  <p>This logic is used for some of my unit tests where I want a function to fail in a certain way. Even if I change the catch to a then block I am still not able to break a series of chained Promises because whatever is returned from the then/catch block will become a Promise that propagates along the chain. </p>
  
  <p>I wonder if Promise is able to achieve this logic; if not, why? It's very strange to me that a Promise chain can never be broken. Thanks!</p>
  
  <p>Edit on 08/16/2015:
  According to the answers given so far, a rejected Promise returned by the then block will propagate through the Promise chain and skip all subsequent then blocks until is is caught (handled). This behavior is well understood because it simply mimics the following synchronous code (approach 1):</p>
  
  <pre><code>try {
    Function1();
    Function2();
    Function3();
    Function4();
  } catch (err) {
    // Assuming this err is thrown in Function1; Function2, Function3 and Function4 will not be executed
    console.log(err);
  }
  </code></pre>
  
  <p>However, what I was asking is the following scenario in synchronous code (approach 2):</p>
  
  <pre><code>try {
    Function1();
  } catch(err) {
    console.log(err); // Function1's error
    return -1; // return immediately
  }
  try {
    Function2();
  } catch(err) {
    console.log(err);
  }
  try {
    Function3();
  } catch(err) {
    console.log(err);
  }
  try {
    Function4();
  } catch(err) {
    console.log(err);
  } 
  </code></pre>
  
  <p>I would like to deal with errors raised in different functions differently. It's possible that I catch all the errors in one catch block as illustrated in approach 1. But that way I have to make a big switch statement inside the catch block to differentiate different errors; moreover, if the errors thrown by different functions do not have a common switchable attribute I won't be able to use the switch statement at all; under such a situation, I have to use a separate try/catch block for each function call. Approach 2 sometimes is the only option. Does Promise not support this approach with its then/catch statement?</p>