summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-02-26 22:01:14 +0000
committerBrett Cannon <bcannon@gmail.com>2007-02-26 22:01:14 +0000
commitc8385efc78cf0e9477c8f14c9829678fe6aa29fe (patch)
tree3e3197e5a70c9520a18ad83f7a64d55a1b7c9cfc /Python
parente85eab6c8445792e1f5eb9369d823dc2a699926d (diff)
downloadcpython-c8385efc78cf0e9477c8f14c9829678fe6aa29fe.tar.gz
Make it so TypeError is raised if an instance of an object is put in an
'except' clause. Also refactor some code to help keep Neal Norwitz happy.
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index fe5de0375a..5cad632c6d 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3895,23 +3895,8 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
}
}
-/*
- Return a true value if the exception is allowed to be in an 'except' clause,
- otherwise return a false value.
-*/
-static int
-can_catch_exc(PyObject *exc)
-{
- if (!(PyExceptionClass_Check(exc) || PyExceptionInstance_Check(exc))) {
- PyErr_SetString(PyExc_TypeError,
- "catching an object must be a class or "
- "instance of BaseException");
- return 0;
- }
- else {
- return 1;
- }
-}
+#define CANNOT_CATCH_MSG "catching classes that do not inherit from"\
+ "BaseException is not allowed"
static PyObject *
cmp_outcome(int op, register PyObject *v, register PyObject *w)
@@ -3941,13 +3926,17 @@ cmp_outcome(int op, register PyObject *v, register PyObject *w)
length = PyTuple_Size(w);
for (i = 0; i < length; i += 1) {
PyObject *exc = PyTuple_GET_ITEM(w, i);
- if (!can_catch_exc(exc)) {
+ if (!PyExceptionClass_Check(exc)) {
+ PyErr_SetString(PyExc_TypeError,
+ CANNOT_CATCH_MSG);
return NULL;
}
}
}
else {
- if (!can_catch_exc(w)) {
+ if (!PyExceptionClass_Check(w)) {
+ PyErr_SetString(PyExc_TypeError,
+ CANNOT_CATCH_MSG);
return NULL;
}
}