# Part 3 — APP Handlers \[Handle Events and Errors]

### Table of contents

1. [Handle HTML events](#step-1-handle-html-events)
2. [Dialog window instead of an error](#step-2-dialog-window-instead-of-an-error)
3. [Results](#step-3-results)

### Step 1 — Handle HTML events

How do I make the IU buttons work?\
It's very simple.\
In the HTML file, I will create a button that invokes the command on **click**:

**src/gui.html** (partially)

```html
<div>
	<el-button
		type="success"
	    	@click="command('normal_handler')">
        		Call normal handler
	 </el-button>
</div>
```

In Python code I will handle this command using callback handler

**src/main.py** (partially)

```python
@app.callback('normal_handler')
def normal_handler(api: sly.Api, task_id, context, state, app_logger):
```

This callback is triggered if the command name matches the name of the callback parameter.\
**Arguments that come to the input:**

* api — api the object of the user who called the callback
* task\_id — app task\_id
* context — information about the environment in which the application is running
* state — state of all widgets in Python dict format
* app\_logger — sly\_logger with task\_id

### Step 2 — Dialog window instead of an error

Sometimes we want the application not to crash after an error occurs.\
Therefore, we can use `app.ignore_errors_and_show_dialog_window()` handler:

**src/main.py** (partially)

```python
@app.callback('error_handler')
@app.ignore_errors_and_show_dialog_window()
def error_handler(api: sly.Api, task_id, context, state, app_logger):
    logger.info('normal handler called')
    raise SystemError('there could be an error message here')
```

### Step 3 — Results

{% embed url="<https://www.youtube.com/watch?v=U2XtONhiZaw>" %}
App Handlers
{% endembed %}


---

# 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://developer.supervisely.com/app-development/advanced/in-depth-app-development/chapter-3-ui/part-3-app-handlers-handle-events-and-errors.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.
