summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2006-03-01 04:25:17 (GMT)
committerBrett Cannon <bcannon@gmail.com>2006-03-01 04:25:17 (GMT)
commitbf36409e2a8171b441d5e0a2f1c9e02d31a35ae8 (patch)
tree7456cf3d197d6f0dc017b0f851878bcaf6024f6c /Include
parent762467475d944f67ac20bf23c6c5144a6e39feae (diff)
downloadcpython-bf36409e2a8171b441d5e0a2f1c9e02d31a35ae8.zip
cpython-bf36409e2a8171b441d5e0a2f1c9e02d31a35ae8.tar.gz
cpython-bf36409e2a8171b441d5e0a2f1c9e02d31a35ae8.tar.bz2
PEP 352 implementation. Creates a new base class, BaseException, which has an
added message attribute compared to the previous version of Exception. It is also a new-style class, making all exceptions now new-style. KeyboardInterrupt and SystemExit inherit from BaseException directly. String exceptions now raise DeprecationWarning. Applies patch 1104669, and closes bugs 1012952 and 518846.
Diffstat (limited to 'Include')
-rw-r--r--Include/pyerrors.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 330a35c..1fe2e45 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -26,9 +26,32 @@ PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *);
PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
+/* */
+#define PyExceptionClass_Check(x) \
+ (PyClass_Check((x)) \
+ || (PyType_Check((x)) && PyType_IsSubtype( \
+ (PyTypeObject*)(x), (PyTypeObject*)PyExc_BaseException)))
+
+
+#define PyExceptionInstance_Check(x) \
+ (PyInstance_Check((x)) || \
+ (PyType_IsSubtype((x)->ob_type, (PyTypeObject*)PyExc_BaseException)))
+
+#define PyExceptionClass_Name(x) \
+ (PyClass_Check((x)) \
+ ? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \
+ : (char *)(((PyTypeObject*)(x))->tp_name))
+
+#define PyExceptionInstance_Class(x) \
+ ((PyInstance_Check((x)) \
+ ? (PyObject*)((PyInstanceObject*)(x))->in_class \
+ : (PyObject*)((x)->ob_type)))
+
+
/* Predefined exceptions */
+PyAPI_DATA(PyObject *) PyExc_BaseException;
PyAPI_DATA(PyObject *) PyExc_Exception;
PyAPI_DATA(PyObject *) PyExc_StopIteration;
PyAPI_DATA(PyObject *) PyExc_GeneratorExit;