> For the complete documentation index, see [llms.txt](https://developer.supervisely.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.supervisely.com/app-development/advanced/in-depth-app-development/chapter-1-headless/part-2-errors-handling-catching-all-bugs.md).

# Part 2 — Errors handling \[Catching all bugs]

### Table of contents

1. [Supervisely logger](#step-1-supervisely-logger)
2. [Use \[try: except\] with traceback](#step-2-use-try-except-with-traceback)
3. [Results](#step-3-results)

### Step 1 — Supervisely logger

Supervisely has a logger. It is a wrapper over Python's built-in [logging](https://docs.python.org/3/howto/logging.html) package.

First thing we need to do is install Supervisely Python SDK to your environment:

```bash
pip install supervisely
```

Let's take the code from Part 1 as a basis and add a logger:

```python
import supervisely_lib as sly

worlds = ['Westeros', 'Azeroth', 'Middle Earth', 'Narnia']

sly_logger = sly.logger

for world in worlds:
    sly_logger.info(f'Hello {world}!')
```

### Step 2 — Use \[try: except] with traceback

To handle errors, you can use the `[try: except]` construction

**src/main.py**

```python
import supervisely_lib as sly

worlds = ['Westeros', 'Azeroth', 'Middle Earth', 'Narnia']

sly_logger = sly.logger

try:
    for world in worlds:
        sly_logger.info(f'Hello {world}!')

    if 'Our World' not in worlds:
        raise ValueError(f"Can't find Our World")

except Exception as ex:
    sly_logger.warning(ex)
```

### Step 3 — Results

{% embed url="<https://www.youtube.com/watch?v=MMcNsW3wI_I>" %}
Error Handling
{% endembed %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://developer.supervisely.com/app-development/advanced/in-depth-app-development/chapter-1-headless/part-2-errors-handling-catching-all-bugs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
