New API PyErr_NewException(name, base, dict) to create simple new exceptions.

This commit is contained in:
Guido van Rossum 1997-09-16 18:43:50 +00:00
parent 0474832d9c
commit 7617e05a9b
1 changed files with 31 additions and 0 deletions

View File

@ -318,3 +318,34 @@ PyErr_Format(exception, format, va_alist)
PyErr_SetString(exception, buffer);
return NULL;
}
PyObject *
PyErr_NewException(name, base, dict)
char *name;
PyObject *base;
PyObject *dict;
{
PyObject *nname = PyString_InternFromString(name);
PyObject *ndict = NULL;
PyObject *nbases = NULL;
PyObject *result = NULL;
if (nname == NULL)
return NULL;
if (dict == NULL) {
dict = ndict = PyDict_New();
if (dict == NULL)
goto failure;
}
if (base == NULL)
base = PyExc_Exception;
nbases = Py_BuildValue("(O)", base);
if (nbases == NULL)
goto failure;
result = PyClass_New(nbases, dict, nname);
failure:
Py_XDECREF(nbases);
Py_XDECREF(ndict);
Py_XDECREF(nname);
return result;
}