Exception Classes
PyObject* PyErr_NewException
(const char name*, PyObject base, PyObject **dict)
Return value: New reference.
This utility function creates and returns a new exception class. The name argument must be the name of the new exception, a C string of the form module.classname
. The base and dict arguments are normally NULL
. This creates a class object derived from Exception
(accessible in C as PyExc_Exception
).
The __module__
attribute of the new class is set to the first part (up to the last dot) of the name argument, and the class name is set to the last part (after the last dot). The base argument can be used to specify alternate base classes; it can either be only one class or a tuple of classes. The dict argument can be used to specify a dictionary of class variables and methods.
PyObject* PyErr_NewExceptionWithDoc
(const char name*, const char doc, PyObject **base, PyObject *dict)
Return value: New reference.
Same as PyErr_NewException()
, except that the new exception class can easily be given a docstring: If doc is non-NULL
, it will be used as the docstring for the exception class.
3.2 新版功能.