summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-03-23 12:46:45 (GMT)
committerGitHub <noreply@github.com>2018-03-23 12:46:45 (GMT)
commit397466dfd905b5132f1c831cd9dff3ecc40b3218 (patch)
tree264d63b490acd0aca934ace77528006bce1d882e /Objects
parent702f8f3611bc49b73772cce2b9b041bd11ff9b35 (diff)
downloadcpython-397466dfd905b5132f1c831cd9dff3ecc40b3218.zip
cpython-397466dfd905b5132f1c831cd9dff3ecc40b3218.tar.gz
cpython-397466dfd905b5132f1c831cd9dff3ecc40b3218.tar.bz2
bpo-30953: Improve error messages and add tests for jumping (GH-6196)
into/out of an except block.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/frameobject.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 9d37935..864a8f9 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -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;