在执行 raise 语句的同时创建异常类,无需提前定义异常类,方便快捷。
Project description
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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for gqylpy_exception-3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b1dabb3a44eda5a6ef2deb427b0d13bd20573905af10cc7d3be31ded2b49d08 |
|
MD5 | 65947f27ee7dbd2325261de5aaf7f14a |
|
BLAKE2b-256 | 446181664b0d804864354d93b3fa8d323b3b423dcba290602b1cb0e31603eed8 |