# 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.

   ![](/files/JA8ImbgbvyC0VEetfXdm)
2. Drag the function `console` to the `tryCatch` function try callback, on it's `value` param add `try` as value.

   ![](/files/qynM4iY0hryOqQqKXQ30)
3. Drag the function `console` to the `tryCatch` function catch callback, on it's `value` param change the param type to `input`.

   ![](/files/q4I2UgDYtoa3APqjScK4)
4. Drag the function `console` to the `tryCatch` function catch callback, on it's `value` param add `finally` as value.

   ![](/files/EaoZ0l0zYTROSWLBRe5G)

### Result

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

   ![](/files/HenoxFJssqS8ljh1SnSu)

## Links

### Related Information

See also:

* Functions
  * [console](/emobiq-client/006-actions-and-visual-logic/action-reference/cordova/app/console.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.emobiq.com/emobiq-client/006-actions-and-visual-logic/action-reference/cordova/flow/trycatch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
