Skip to content

Raise exceptions while creating exception classes on the fly, without the need to predefine them beforehand.

License

Notifications You must be signed in to change notification settings

gqylpy/gqylpy-exception

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LOGO Release Python Versions License Downloads

gqylpy-exception

English | 中文

Raise exceptions while creating exception classes on the fly, without the need to predefine them beforehand. For instance, if you want to raise an exception named NotUnderstandError, simply import import gqylpy_exception as ge and execute raise ge.NotUnderstandError directly for convenience and efficiency.

pip3 install gqylpy_exception

Using gqylpy_exception to Create Exception Classes
import gqylpy_exception as ge

raise ge.AnError(...)

With gqylpy_exception, you can create exception classes with arbitrary names. AnError is not predefined in gqylpy_exception; it is dynamically created when your code executes ge. due to the magic method __getattr__.

Alternatively, you can also create exceptions upon import:

from gqylpy_exception import AnError

raise AnError(...)

Lastly, gqylpy_exception avoids duplicate creation of exception classes. Once an exception class has been created, it is stored in the ge.__history__ dictionary. When you attempt to create the same exception again, it will be retrieved from this dictionary.

About

Raise exceptions while creating exception classes on the fly, without the need to predefine them beforehand.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages