tryCatch

Description

Handling exceptions (errors) in code execution. It allows you to "try" a block of code, "catch" any errors that occur, and optionally "finally" execute some code regardless of whether an error was thrown or not

Input / Parameter

N/A

Output

N/A

Callback

try callback

The functions to be executed.

catch callback

The functions to be executed when there is an exception.

Description
Output Type

Returns an error.

Error

finally callback

The functions to be executed regardless of the exception is thrown or caught.

Example

In this example, we will do console logging by using console function in tryCatch function callback to demonstrate how tryCatch works.

Code Equivalent

try {
  console.log("try")
} catch (e) {
  console.log(e)
} finally {
  console.log("finally");
}

Steps

  1. Drag a button component into the canvas and open the Action tab. Select the press event of the button and drag the tryCatch function to the event flow.

  2. Drag the function console to the tryCatch function try callback, on it's value param add try as value.

  3. Drag the function console to the tryCatch function catch callback, on it's value param change the param type to input.

  4. Drag the function console to the tryCatch function catch callback, on it's value param add finally as value.

Result

  1. Now click the button in preview, it will only show try and finally on the console.

See also:

Last updated