mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-30953: Improve error messages and add tests for jumping (GH-6196)
into/out of an except block.
This commit is contained in:
parent
702f8f3611
commit
397466dfd9
2 changed files with 74 additions and 12 deletions
|
@ -277,8 +277,12 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
|
|||
int first_in = target_addr <= f->f_lasti && f->f_lasti <= addr;
|
||||
int second_in = target_addr <= new_lasti && new_lasti <= addr;
|
||||
if (first_in != second_in) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"can't jump into or out of a 'finally' block");
|
||||
op = code[target_addr];
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"can't jump %s %s block",
|
||||
second_in ? "into" : "out of",
|
||||
(op == DUP_TOP || op == POP_TOP) ?
|
||||
"an 'except'" : "a 'finally'");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue