# How to retry a node when there is an exception?

**URL:** <https://discourse.nodered.org/t/how-to-retry-a-node-when-there-is-an-exception/63145>\
**Category:** General\
**Created:** [27 May 2022 10:49 UTC](https://discourse.nodered.org/t/how-to-retry-a-node-when-there-is-an-exception/63145 "2022-05-27T10:49:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/josh/32/62208_2.png) [@Josh](https://discourse.nodered.org/u/Josh)\
**Post date:** [27 May 2022 10:49 UTC](https://discourse.nodered.org/t/how-to-retry-a-node-when-there-is-an-exception/63145/1 "2022-05-27T10:49:28Z")

</div>

I am trying to create a generic flow to retry a node when there is an exception thrown. Can someone try to help me?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 May 2022 11:57 UTC](https://discourse.nodered.org/t/how-to-retry-a-node-when-there-is-an-exception/63145/2 "2022-05-27T11:57:07Z")

</div>

Have a look at the `catch` node. It is able to intercept exceptions (as long as they are correctly coded in the node that produces them) and trigger a flow.

---

<div class="post-metadata">

**Author:** ![Josh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/josh/32/62208_2.png) [@Josh](https://discourse.nodered.org/u/Josh)\
**Post date:** [30 May 2022 06:03 UTC](https://discourse.nodered.org/t/how-to-retry-a-node-when-there-is-an-exception/63145/3 "2022-05-30T06:03:37Z")

</div>

Firstly thanks for replying...  
**(as long as they are correctly coded in the node that produces them) --**  
I am trying to get a point in the above line which you said. Do we need to code in the node to throw an error should an error occur in a node? If so, what about the nodes that we download from palette?=

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [30 May 2022 19:18 UTC](https://discourse.nodered.org/t/how-to-retry-a-node-when-there-is-an-exception/63145/4 "2022-05-30T19:18:30Z")

</div>

When a node may hit an error, it should trap it using try/catch or the equivalent for promises. For Node-RED to be able to handle errors gracefully, including using the catch node, the node should issue a `node.error` and include the error object as the 2nd argument (the first being an error description string).

A well coded node will include that.

Of course, there are some errors that shouldn't be trapped and those are ones that would leave the node-red runtime in an uncertain state. By-and-large though, errors should be trapped and passed gracefully.

So no, you don't need code in your flow in order to handle errors. An error occurring in a function node for example, should not generally be able to crash node-red as function nodes use a node.js VM to run in.

However, if a node that you use encounters an error and has prepared for it as described, you can use a `catch` node to detect the error and start a different flow to handle it.

Nodes downloaded from the palette _should_ be well coded if they have followed the documentation. But we all make mistakes and some people don't read documentation. So no guarantees I'm afraid.

---

<div class="post-metadata">

**Author:** ![Josh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/josh/32/62208_2.png) [@Josh](https://discourse.nodered.org/u/Josh)\
**Post date:** [21 July 2022 05:32 UTC](https://discourse.nodered.org/t/how-to-retry-a-node-when-there-is-an-exception/63145/5 "2022-07-21T05:32:16Z")

</div>

Thanks for the clearup !!! Much useful

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [19 September 2022 05:32 UTC](https://discourse.nodered.org/t/how-to-retry-a-node-when-there-is-an-exception/63145/6 "2022-09-19T05:32:56Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
