diff Include/pyerrors.h @ 36751:8e04de2480e4 legacy-trunk

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.
author Brett Cannon <bcannon@gmail.com>
date Wed, 01 Mar 2006 04:25:17 +0000
parents 7fdc639bc5b4
children b5e7d5b3c442 49c6eb688906
line wrap: on
line diff
--- a/Include/pyerrors.h	Wed Mar 01 04:06:10 2006 +0000
+++ b/Include/pyerrors.h	Wed Mar 01 04:25:17 2006 +0000
@@ -26,9 +26,32 @@
 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;