Skip to main content

在执行 raise 语句的同时创建异常类,无需提前定义异常类,方便快捷。

Project description

LOGO Release Python Versions License Downloads

gqylpy-exception

在执行 raise 语句的同时创建异常类,无需提前定义异常类,方便快捷。例如,你想抛出一个名为 NotUnderstandError 的异常, 导入 import gqylpy_exception as ge 后直接执行 raise ge.NotUnderstandError 即可。

pip3 install gqylpy_exception

使用 gqylpy_exception 创建异常类
import gqylpy_exception as ge

raise ge.AnError(...)

gqylpy_exception 可以创建任意名称的异常类。AnError 不是 gqylpy_exception 中内置的,它是在你的代码执行到 ge. 时创建的,魔化方法 __getattr__ 的特性。

还有一种用法,导入即创建:

from gqylpy_exception import AnError

raise AnError(...)

最后,gqylpy_exception 不会重复创建异常类,创建过的异常类将存入 ge.__history__ 字典,当你再次创建时从这个字典中取值。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gqylpy_exception-3.0.tar.gz (11.5 kB view hashes)

Uploaded Source

Built Distribution

gqylpy_exception-3.0-py3-none-any.whl (12.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page