> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/debug/handling/rethrow.md).

# rethrow

* [JS](/web/js.md) ⟩ [statement](/web/js/grammar/statement.md) ⟩ [control flow](/web/js/grammar/statement/flow.md) ⟩ [jump](/web/js/grammar/statement/flow/jump.md) ⟩ rethrow
* [JS](/web/js.md) ⟩ [error](/web/js/err.md) ⟩ [handling](/web/js/debug/handling.md) ⟩ rethrow&#x20;

{% hint style="success" %}
rethrows an unexpected error.&#x20;

```javascript
try {
    functionThatThrows();
} catch (err) {
    if (err instanceof InputError) { ... } 
    else { throw err }                        // ⭐️ rethrow
}
```

{% endhint %}

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

```javascript
// custom Error
class InputError extends Error {}

// function that may throw
function functionThatThrows() {
    // ...
    throw new InputError("Invalid input");
}

try {
    functionThatThrows();
} catch (err) {
    if (err instanceof InputError) { ... } 
    else { throw err }                        // ⭐️ rethrow
}
```

{% endtab %}

{% tab title="📗 參考" %}

* [ ] Eloquent JavaScript ⟩ [Selective Catching](https://eloquentjavascript.net/08_error.html#h_vfoJqEDazI) ⭐️&#x20;
* [ ] [JavaScript: The Definitive Guide](/web/master/ref/javascript-the-definitive-guide.md) ⟩ 5.5.6 throw
  {% endtab %}

{% tab title="📘 手冊" %}

* [throw](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw)
  {% endtab %}
  {% endtabs %}
