Skip to content

Commit a001ff9

Browse files
author
guido.van.rossum
committed
Issue #2341: Add a Py3k warning when raising an exception that doesn't
derive from BaseException. git-svn-id: http://svn.python.org/projects/python/trunk@61486 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent e8b0336 commit a001ff9

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Core and builtins
1313
-----------------
1414

1515
- Issue #2371: Add a Py3k warning when catching an exception that
16-
doesn't derive from BaseException.
16+
doesn't derive from BaseException. Issue #2341: Add a Py3k warning
17+
when raising an exception that doesn't derive from BaseException.
1718

1819
- Issue #2321: use pymalloc for unicode object string data to reduce
1920
memory usage in some circumstances.

Python/ceval.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3161,6 +3161,15 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
31613161
type->ob_type->tp_name);
31623162
goto raise_error;
31633163
}
3164+
3165+
assert(PyExceptionClass_Check(type));
3166+
if (Py_Py3kWarningFlag && PyClass_Check(type)) {
3167+
if (PyErr_Warn(PyExc_DeprecationWarning,
3168+
"exceptions must derive from BaseException "
3169+
"in 3.x") == -1)
3170+
goto raise_error;
3171+
}
3172+
31643173
PyErr_Restore(type, value, tb);
31653174
if (tb == NULL)
31663175
return WHY_EXCEPTION;

0 commit comments

Comments
 (0)