Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
bee07122
Commit
bee07122
authored
Mar 25, 2006
by
Phillip J. Eby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support throw() of string exceptions.
parent
43b00da2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
Lib/test/test_generators.py
Lib/test/test_generators.py
+4
-2
Objects/genobject.c
Objects/genobject.c
+4
-1
No files found.
Lib/test/test_generators.py
View file @
bee07122
...
...
@@ -1545,6 +1545,9 @@ caught ValueError (1)
>>> g.throw(ValueError, TypeError(1)) # mismatched type, rewrapped
caught ValueError (1)
>>> g.throw(ValueError, ValueError(1), None) # explicit None traceback
caught ValueError (1)
>>> g.throw(ValueError(1), "foo") # bad args
Traceback (most recent call last):
...
...
...
@@ -1592,8 +1595,7 @@ ValueError: 7
>>> f().throw("abc") # throw on just-opened generator
Traceback (most recent call last):
...
TypeError: exceptions must be classes, or instances, not str
abc
Now let's try closing a generator:
...
...
Objects/genobject.c
View file @
bee07122
...
...
@@ -249,7 +249,10 @@ gen_throw(PyGenObject *gen, PyObject *args)
Py_INCREF
(
typ
);
}
}
else
{
/* Allow raising builtin string exceptions */
else
if
(
!
PyString_CheckExact
(
typ
))
{
/* Not something you can raise. throw() fails. */
PyErr_Format
(
PyExc_TypeError
,
"exceptions must be classes, or instances, not %s"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment