summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-09-16 18:43:50 (GMT)
committerGuido van Rossum <guido@python.org>1997-09-16 18:43:50 (GMT)
commit7617e05a9befb3fdf1c4727f6fa0a79ff783b186 (patch)
tree429e48d18b29fdd41247fc51e35cc44799e47873 /Python/errors.c
parent0474832d9c6c708d8addd31a989dff772fdfefbf (diff)
downloadcpython-7617e05a9befb3fdf1c4727f6fa0a79ff783b186.zip
cpython-7617e05a9befb3fdf1c4727f6fa0a79ff783b186.tar.gz
cpython-7617e05a9befb3fdf1c4727f6fa0a79ff783b186.tar.bz2
New API PyErr_NewException(name, base, dict) to create simple new exceptions.
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 91c543d..31d9cdf 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -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;
+}