# recoverable errors

{% tabs %}
{% tab title="⭐️ 重點" %}
{% hint style="success" %}

* [.catch()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) **callback** is for：
  * <mark style="color:yellow;">**reporting**</mark> errors
  * <mark style="color:yellow;">**handling**</mark> errors&#x20;
  * <mark style="color:orange;">**recovering**</mark> from errors ⭐️
    {% endhint %}

{% hint style="warning" %}

* [.catch()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch) **callback** can throw a new error, but if it <mark style="color:yellow;">**returns normally**</mark>, than that <mark style="color:orange;">**return value**</mark> is used to <mark style="color:yellow;">**resolve**</mark> (fulfill) the associated [..](https://lochiwei.gitbook.io/web/js/async/promise "mention"), and the <mark style="color:red;">**error stops propagating**</mark>.
  {% endhint %}
  {% endtab %}

{% tab title="💈範例" %}

```javascript
// recover from errors
asyncOperation()
    .then(doStage2)
    
    // ⭐️ catch recoverable errors from stage 2
    // ---------------------------------------------------------
    // if `recoverableErrors` returns normally, its return value
    // is passed to `doStage3` and continues normally.
    .catch(recoverableErrors)     
    
    .then(doStage3) 
    .then(doStage4) 
    .catch(stage3And4Errors);
    
// recover from network problems
queryDatabase() 

     // ⭐️ wait and retry (`wait` is fictional)
    .catch(e => wait(500).then(queryDatabase))
    
    .then(displayTable) 
    .catch(displayDatabaseError);
```

{% endtab %}
{% endtabs %}
