The Try-Catch-Finally node consists of a Try connector followed by one or more Catch connectors, which specify handlers for different exceptions.

You can execute some code in a Try block that can contain errors, and if they happen the Catch block will be executed and you can get the exception from the Catch:Exception_N pin.

The Finally connector will be executed anyway. You can clean up any resources that are allocated in a Try block, and you can run code even if an exception occurs in the try block.

The Next code connector is used for executing code that goes after the Try-Catch-Finally node.


Using example

In this example we will try to print the name of the GameObject, and if it is null the Catch block will be executed with an exception (null reference exception), which will be logged into the console:

Note: in this case it’s better to use nodes “If” and “is null” node instead of a Try-Catch-Finally.

Render time: 0.01 seconds
137,012 unique visits