summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-02-26 21:10:16 (GMT)
committerBrett Cannon <bcannon@gmail.com>2007-02-26 21:10:16 (GMT)
commitf74225d63b84a4d3b508fd5657cfe2596633876a (patch)
tree572bea5b82c03c9b9267944370a2f43be0dd7945 /Lib
parent6baa4c4cc6d303bfdac7c6fd21371f3bc48c7e06 (diff)
downloadcpython-f74225d63b84a4d3b508fd5657cfe2596633876a.zip
cpython-f74225d63b84a4d3b508fd5657cfe2596633876a.tar.gz
cpython-f74225d63b84a4d3b508fd5657cfe2596633876a.tar.bz2
You can no longer catch non-BaseException objects; TypeError is raised if such
an object is listed in an 'except' clause.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_pep352.py37
1 files changed, 10 insertions, 27 deletions
diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py
index 15f1101..2a6bac1 100644
--- a/Lib/test/test_pep352.py
+++ b/Lib/test/test_pep352.py
@@ -158,34 +158,17 @@ class UsageTests(unittest.TestCase):
# Raising a string raises TypeError.
self.raise_fails("spam")
+ def test_catch_non_BaseException(self):
+ # Tryinng to catch an object that does not inherit from BaseException
+ # is not allowed.
+ class NonBaseException(object):
+ pass
+ self.catch_fails(NonBaseException)
+ self.catch_fails(NonBaseException())
+
def test_catch_string(self):
- # Catching a string should trigger a DeprecationWarning.
- with guard_warnings_filter():
- warnings.resetwarnings()
- warnings.filterwarnings("error")
- str_exc = "spam"
- try:
- try:
- raise StandardError
- except str_exc:
- pass
- except DeprecationWarning:
- pass
- except StandardError:
- self.fail("catching a string exception did not raise "
- "DeprecationWarning")
- # Make sure that even if the string exception is listed in a tuple
- # that a warning is raised.
- try:
- try:
- raise StandardError
- except (AssertionError, str_exc):
- pass
- except DeprecationWarning:
- pass
- except StandardError:
- self.fail("catching a string exception specified in a tuple did "
- "not raise DeprecationWarning")
+ # Catching a string is bad.
+ self.catch_fails("spam")
def test_main():
run_unittest(ExceptionClassTests, UsageTests)