Commit bee07122 authored by Phillip J. Eby's avatar Phillip J. Eby

Support throw() of string exceptions.

parent 43b00da2
...@@ -1545,6 +1545,9 @@ caught ValueError (1) ...@@ -1545,6 +1545,9 @@ caught ValueError (1)
>>> g.throw(ValueError, TypeError(1)) # mismatched type, rewrapped >>> g.throw(ValueError, TypeError(1)) # mismatched type, rewrapped
caught ValueError (1) caught ValueError (1)
>>> g.throw(ValueError, ValueError(1), None) # explicit None traceback
caught ValueError (1)
>>> g.throw(ValueError(1), "foo") # bad args >>> g.throw(ValueError(1), "foo") # bad args
Traceback (most recent call last): Traceback (most recent call last):
... ...
...@@ -1592,8 +1595,7 @@ ValueError: 7 ...@@ -1592,8 +1595,7 @@ ValueError: 7
>>> f().throw("abc") # throw on just-opened generator >>> f().throw("abc") # throw on just-opened generator
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: exceptions must be classes, or instances, not str abc
Now let's try closing a generator: Now let's try closing a generator:
......
...@@ -249,7 +249,10 @@ gen_throw(PyGenObject *gen, PyObject *args) ...@@ -249,7 +249,10 @@ gen_throw(PyGenObject *gen, PyObject *args)
Py_INCREF(typ); Py_INCREF(typ);
} }
} }
else {
/* Allow raising builtin string exceptions */
else if (!PyString_CheckExact(typ)) {
/* Not something you can raise. throw() fails. */ /* Not something you can raise. throw() fails. */
PyErr_Format(PyExc_TypeError, PyErr_Format(PyExc_TypeError,
"exceptions must be classes, or instances, not %s", "exceptions must be classes, or instances, not %s",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment