Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Utility wrapper class to handle exceptions.
Python >= 3.8
You can install trier
from PyPI, with pip
:
python -m pip install trier
Instead of using try except
block you could replace it with trier
.
from trier import Try
err, val = Try(lambda: 10 / 0).catch(ZeroDivisionError)
if err:
# handle error
# do stuff with `val`
# Another way to handle could be
if not err:
# do stuff with `val`
Supports multiple exceptions.
from trier import Try
err, file = Try(open, file="doenot_exist.txt").catch(FileNotFoundError, OSError)
if err:
# handle error
# do stuff with `file`
Supports async error handling as well.
import asyncio
from httpx import AsyncClient, HTTPStatusError, Response
from trier import Try
def raise_on_4xx_5xx(response):
response.raise_for_status()
async def main():
client = AsyncClient(event_hooks={"response": [raise_on_4xx_5xx]})
# The endpoint responds with a 404 error
err, response = await Try(client.get, "https://run.mocky.io/v3/201f1fe6-5a3b-49c1-9df7-312951618405").async_catch(HTTPStatusError)
if err:
# Handle error
# do stuff with `response`
asyncio.run(main())
Refer to the CHANGELOG.
MIT - See the LICENSE for more information.
FAQs
Utility wrapper to handle exceptions.
We found that trier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.