# Errors and Exceptions

{% embed url="<https://www.hackerrank.com/domains/python?filters%5Bsubdomains%5D%5B%5D=errors-exceptions>" %}

## Exceptions

<figure><img src="/files/UwkDyVrGm32ZvPsRc966" alt=""><figcaption></figcaption></figure>

{% code lineNumbers="true" %}

```python
for i in range(int(input())):
    try:
        a, b = map(str, input().strip().split(' '))
        print(int(a) // int(b))
    except ValueError as e:
        print(f"Error Code: {e}")
    except ZeroDivisionError as e:
        print(f"Error Code: {e}")
```

{% endcode %}

***

## Incorrect Regex

<figure><img src="/files/PKk8XnveyKeLHPzH11mf" alt=""><figcaption></figcaption></figure>

```python
# Run with pypy3
import re

for _ in range(int(input())):
    regex = input()
    try:
        re.compile(regex)
        print(True)
    except re.error:
        print(False)
```


---

# 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://thamizhiniyancs.gitbook.io/writeups/hackerrank/python/errors-and-exceptions.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.
