# Need help with how to add catch node to catch errors if any

**URL:** <https://discourse.nodered.org/t/need-help-with-how-to-add-catch-node-to-catch-errors-if-any/42777>\
**Category:** General\
**Created:** [17 March 2021 17:13 UTC](https://discourse.nodered.org/t/need-help-with-how-to-add-catch-node-to-catch-errors-if-any/42777 "2021-03-17T17:13:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SKA](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@SKA](https://discourse.nodered.org/u/SKA)\
**Post date:** [17 March 2021 17:13 UTC](https://discourse.nodered.org/t/need-help-with-how-to-add-catch-node-to-catch-errors-if-any/42777/1 "2021-03-17T17:13:59Z")

</div>

Hello all I need some urgent help please, my final goal is to compare incoming RGB values with the stored ones in the database, but before that I am trying to use error handling to catch any errors. For example if the values don't match or if it is not reading the values. I am fairly new to NodeRED and I am not sure how to use catch node with the flow I have and display any error if there is any. Also, I am not sure if it possible to do auditory warning in NodeRED like a beep sounds when there's error or a warning.  
Below is my flow and I am trying to connect the catch with the RGB flow, but I am not sure how.  
Any help that I can get would be great. Please point me to right direction.

```auto
[{"id":"62a5cdb9.d00914","type":"catch","z":"7515c9c5.2674a8","name":"All Error","scope":null,"uncaught":false,"x":210,"y":220,"wires":[["1cc5bf15.178c21"]]},{"id":"1cc5bf15.178c21","type":"debug","z":"7515c9c5.2674a8","name":"Error","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"error.message","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":220,"wires":[]},{"id":"e8c53894.84c708","type":"inject","z":"7515c9c5.2674a8","name":"Reading","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"R:212 ,G: 243,B: 290","payloadType":"str","x":180,"y":100,"wires":[["a2691a30.b117d8"]]},{"id":"84aa9c8f.818f8","type":"function","z":"7515c9c5.2674a8","name":"Comparison ","func":"msg.payload = Number (msg.payload);\n//msg.payload = Number (msg.payload.split(\":\")[1]);\nmsg.R; // new stored value\nvar actualRed = 250;\n\n//comapring reading and the actual value for red\nif(msg.payload <= 0 || isNaN(msg.payload))\n{\n msg.R = \"Unable to read sensor\";\n return msg;\n}\nelse if (msg.payload == actualRed)\n{\n msg.R = msg.payload;\n return msg;\n}\nelse if(msg.payload > actualRed)\n{\n correction = msg.payload - actualRed;\n msg.R = msg.payload - correction;\n return msg;\n}\nelse\nif(msg.payload < actualRed)\n{\n correction = actualRed - msg.payload;\n msg.R = msg.payload + correction;\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":40,"wires":[["7af328ef.98e338"]]},{"id":"89d059cb.f5c728","type":"switch","z":"7515c9c5.2674a8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"R:","vt":"str"},{"t":"cont","v":"G:","vt":"str"},{"t":"cont","v":"B:","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":490,"y":100,"wires":[["37e1b4a3.c4f72c"],["57a29b8a.95cd94"],["313d7004.fca86"]]},{"id":"7af328ef.98e338","type":"debug","z":"7515c9c5.2674a8","name":"Red","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"R","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":40,"wires":[]},{"id":"3ba7a791.cdb6c8","type":"switch","z":"7515c9c5.2674a8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"lte","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":40,"wires":[["84aa9c8f.818f8"],["84aa9c8f.818f8"]]},{"id":"8696e98f.fdf5b8","type":"switch","z":"7515c9c5.2674a8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"lte","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":100,"wires":[["9bd7d76.0c43728"],["9bd7d76.0c43728"]]},{"id":"35a0cd11.ee1a92","type":"switch","z":"7515c9c5.2674a8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"},{"t":"lte","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":160,"wires":[["2b02062f.144e7a"],["2b02062f.144e7a"]]},{"id":"9bd7d76.0c43728","type":"function","z":"7515c9c5.2674a8","name":"Comparison","func":"msg.payload = Number (msg.payload);\n//msg.payload = Number (msg.payload.split(\":\")[1]);\nmsg.G; // new stored value\nvar actualGreen = 252;\n\n//comapring reading and the actual value for red\nif(msg.payload <= 0 || isNaN(msg.payload))\n{\n msg.G = \"Unable to read sensor\";\n return msg;\n}\nelse if (msg.payload == actualGreen)\n{\n msg.G = msg.payload;\n return msg;\n}\nelse if(msg.payload > actualGreen)\n{\n correction = msg.payload - actualGreen;\n msg.G = msg.payload - correction;\n return msg;\n}\nelse\nif(msg.payload < actualGreen)\n{\n correction = actualGreen - msg.payload;\n msg.G = msg.payload + correction;\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":100,"wires":[["726dbc24.ead884"]]},{"id":"2b02062f.144e7a","type":"function","z":"7515c9c5.2674a8","name":"Comparison","func":"msg.payload = Number (msg.payload);\n//msg.payload = Number (msg.payload.split(\":\")[1]);\nmsg.B; // new stored value\nvar actualBlue = 251;\n\n//comapring reading and the actual value for red\nif(msg.payload <= 0 || isNaN(msg.payload))\n{\n msg.B = \"Unable to read sensor\";\n return msg;\n}\nelse if (msg.payload == actualBlue)\n{\n msg.B = msg.payload;\n return msg;\n}\nelse if(msg.payload > actualBlue)\n{\n correction = msg.payload - actualBlue;\n msg.B = msg.payload - correction;\n return msg;\n}\nelse\nif(msg.payload < actualBlue)\n{\n correction = actualBlue - msg.payload;\n msg.B = msg.payload + correction;\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":160,"wires":[["87240585.c93ba8"]]},{"id":"91428168.6a945","type":"inject","z":"7515c9c5.2674a8","name":"RGB<0","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"R: 0 ,G: 0 ,B: 0","payloadType":"str","x":210,"y":140,"wires":[["a2691a30.b117d8"]]},{"id":"a2691a30.b117d8","type":"split","z":"7515c9c5.2674a8","name":"","splt":",","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":350,"y":100,"wires":[["89d059cb.f5c728"]]},{"id":"313d7004.fca86","type":"split","z":"7515c9c5.2674a8","name":"","splt":":","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":670,"y":160,"wires":[["35a0cd11.ee1a92"]]},{"id":"57a29b8a.95cd94","type":"split","z":"7515c9c5.2674a8","name":"","splt":":","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":670,"y":100,"wires":[["8696e98f.fdf5b8"]]},{"id":"37e1b4a3.c4f72c","type":"split","z":"7515c9c5.2674a8","name":"","splt":":","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":670,"y":40,"wires":[["3ba7a791.cdb6c8"]]},{"id":"726dbc24.ead884","type":"debug","z":"7515c9c5.2674a8","name":"Green","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"G","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":100,"wires":[]},{"id":"87240585.c93ba8","type":"debug","z":"7515c9c5.2674a8","name":"Blue","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"B","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":160,"wires":[]},{"id":"c69d0667.e2ed78","type":"comment","z":"7515c9c5.2674a8","name":"Imcoming RGB","info":"","x":160,"y":60,"wires":[]}]

```

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 March 2021 00:07 UTC](https://discourse.nodered.org/t/need-help-with-how-to-add-catch-node-to-catch-errors-if-any/42777/2 "2021-03-18T00:07:23Z")

</div>

the `catch` node is used to 'catch' errors thrown by a node, not things you determine are errors in your flow. for example, in your `function` nodes, you are deciding that the data is not correct. For a node to throw an error it might find the input data format is not correct - maybe it is looking for an object and you pass it a string.

That said, the `function` node can have multiple output so you could use one to send valid date to a series of nodes while the other could be used to send the msg to a series of ndes that will handle the error(s).

Make sure you read the [documentation about the `function` node](https://nodered.org/docs/user-guide/writing-functions) to see how you can do this.

---

<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:** [17 May 2021 00:08 UTC](https://discourse.nodered.org/t/need-help-with-how-to-add-catch-node-to-catch-errors-if-any/42777/3 "2021-05-17T00:08:03Z")

</div>

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