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
8bf7c484
Commit
8bf7c484
authored
Jan 26, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow classes as exceptions
parent
8ae87c04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
Python/ceval.c
Python/ceval.c
+26
-4
No files found.
Python/ceval.c
View file @
8bf7c484
...
...
@@ -783,13 +783,33 @@ eval_code(co, globals, locals, owner, arg)
u
=
w
;
w
=
gettupleitem
(
u
,
0
);
INCREF
(
w
);
INCREF
(
w
);
DECREF
(
u
);
}
if
(
!
is_stringobject
(
w
))
err_setstr
(
TypeError
,
"exceptions must be strings"
);
else
if
(
is_stringobject
(
w
))
{
err_setval
(
w
,
v
);
}
else
if
(
is_classobject
(
w
))
{
if
(
!
is_instanceobject
(
v
)
||
!
issubclass
((
object
*
)((
instanceobject
*
)
v
)
->
in_class
,
w
))
err_setstr
(
TypeError
,
"a class exception must have a value that is an instance of the class"
);
else
err_setval
(
w
,
v
);
}
else
if
(
is_instanceobject
(
w
))
{
if
(
v
!=
None
)
err_setstr
(
TypeError
,
"an instance exception may not have a separate value"
);
else
{
DECREF
(
v
);
v
=
w
;
w
=
(
object
*
)
((
instanceobject
*
)
w
)
->
in_class
;
INCREF
(
w
);
err_setval
(
w
,
v
);
}
}
else
err_setstr
(
TypeError
,
"exceptions must be strings, classes, or instances"
);
DECREF
(
v
);
DECREF
(
w
);
why
=
WHY_EXCEPTION
;
...
...
@@ -2393,6 +2413,8 @@ cmp_exception(err, v)
}
return
0
;
}
if
(
is_classobject
(
v
)
&&
is_classobject
(
err
))
return
issubclass
(
err
,
v
);
return
err
==
v
;
}
...
...
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