diff -r fa23f323d747 Lib/test/test_ast.py --- a/Lib/test/test_ast.py Tue Mar 08 16:49:57 2011 +0200 +++ b/Lib/test/test_ast.py Tue Mar 08 22:04:04 2011 +0100 @@ -204,6 +204,15 @@ compile(m, "", "exec") self.assertIn("but got <_ast.expr", str(cm.exception)) + def test_issue11441(self): + # issue11441: test if a syntax error in an + # except clause raises the correct exception + with self.assertRaises(SyntaxError): + try: + raise Exception() + except Exception: + compile('1 = 1', '', 'exec') + class ASTHelpers_Test(unittest.TestCase): diff -r fa23f323d747 Python/ast.c --- a/Python/ast.c Tue Mar 08 16:49:57 2011 +0200 +++ b/Python/ast.c Tue Mar 08 22:04:04 2011 +0100 @@ -109,6 +109,15 @@ return; PyErr_Fetch(&type, &value, &tback); + if (PyExceptionInstance_Check(value)) { + /* value is not a tuple but an exception instance */ + tmp = ((PyBaseExceptionObject *) value)->args; + Py_INCREF(tmp); + Py_DECREF(value); + value = tmp; + } + assert(PyTuple_Check(value)); + errstr = PyTuple_GetItem(value, 0); if (!errstr) return; @@ -150,6 +159,7 @@ Py_DECREF(tmp); if (!value) return; + PyErr_NormalizeException(&type, &value, &tback); PyErr_Restore(type, value, tback); }