Metadata-Version: 2.4
Name: exceptionx
Version: 0.0a1
Summary: The `exceptionx` is a flexible and convenient Python exception handling library that allows you to dynamically create exception classes and provides various exception handling mechanisms.
Home-page: http://gqylpy.com
Author: Unnamed great master
Author-email: <gqylpy@outlook.com>
License: MIT
Project-URL: Source, https://github.com/gqylpy/exceptionx
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: Chinese (Simplified)
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Bug Tracking
Classifier: Topic :: Software Development :: Widget Sets
Classifier: Topic :: Artistic Software
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=2.7
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: requires-python
Dynamic: summary

[<img alt="LOGO" src="https://python.org/favicon.ico" height="21" width="21"/>](http://gqylpy.com)
[![Release](https://img.shields.io/github/release/gqylpy/exceptionx.svg?style=flat-square")](https://github.com/gqylpy/exceptionx/releases/latest)
[![Python Versions](https://img.shields.io/badge/python-2.7+/3.6+-blue.svg)](https://pypi.org/project/exceptionx)
[![License](https://img.shields.io/pypi/l/exceptionx)](https://github.com/gqylpy/exceptionx/blob/main/LICENSE)
[![Downloads](https://static.pepy.tech/badge/exceptionx)](https://pepy.tech/project/exceptionx)

# exceptionx
English | [中文](https://github.com/gqylpy/exceptionx/blob/main/README_CN.md)

__exceptionx__ is a flexible and convenient Python exception handling library that provides multiple exception handling mechanisms.
> The predecessor of exceptionx is [gqylpy-exception](https://github.com/gqylpy/gqylpy-exception).

<kbd>pip install exceptionx</kbd>

## Powerful Exception Handling Capabilities

exceptionx provides a series of powerful exception handling tools:

- `TryExcept`: A decorator that catches exceptions raised in the decorated function and outputs the exception information to the terminal (instead of throwing it). This helps prevent the program from crashing due to unhandled exceptions.
- `Retry`: A decorator that works similarly to `TryExcept` but attempts to re-execute the function, controlling the number of attempts and the interval between each retry through parameters. It throws an exception after reaching the maximum number of attempts.
- `TryContext`: A context manager that allows you to easily catch exceptions raised in a code block using the `with` statement and output the exception information to the terminal.

**Handling Exceptions in Functions with `TryExcept`**

```python
from exceptionx import TryExcept

@TryExcept(ValueError)
def func():
    int('a')
```

The default handling scheme is to output brief exception information to the terminal without interrupting program execution. Of course, it can also be output to logs or processed in other ways through parameters.

> According to Python programming conventions, exception types should be explicitly specified when handling exceptions. Therefore, when using the `TryExcept` decorator, it is necessary to explicitly pass the handled exception types.

**Retrying Exceptions in Functions with `Retry`**

```python
from exceptionx import Retry

@Retry(sleep=1, count=3)
def func():
    int('a')
```

If an exception is raised in the decorated function, it will attempt to re-execute the decorated function. The default behavior is to retry exceptions of type `Exception` and all its subclasses. Calling `Retry(sleep=1, count=3)` as above means a maximum of 3 attempts will be made, with a 1-second interval between each attempt.

`Retry` can be used in combination with `TryExcept` to retry exceptions first and then handle them if the retries are unsuccessful:

```python
from exceptionx import TryExcept, Retry

@TryExcept(ValueError)
@Retry(sleep=1, count=3)
def func():
    int('a')
```

**Handling Exceptions in Contexts with `TryContext`**

```python
from exceptionx import TryContext

with TryContext(ValueError):
    int('a')
```

With exceptionx, you can handle exceptions in Python programs more flexibly and efficiently, enhancing the robustness and reliability of your code.
