diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-30 00:51:58 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-30 00:51:58 (GMT) |
commit | 7d5fbaee4254f7c06f193359b8e713c6146b0821 (patch) | |
tree | c50b2fc45c3df6cb571c9074967125157aff26bf /Doc | |
parent | 7d518f418b8bb7f155c8e695adbc5b69ac0ed0fd (diff) | |
download | cpython-7d5fbaee4254f7c06f193359b8e713c6146b0821.zip cpython-7d5fbaee4254f7c06f193359b8e713c6146b0821.tar.gz cpython-7d5fbaee4254f7c06f193359b8e713c6146b0821.tar.bz2 |
Demonstrate new except/as syntax.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/tutorial/errors.rst | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Doc/tutorial/errors.rst b/Doc/tutorial/errors.rst index ba0cbb3..8f14e44 100644 --- a/Doc/tutorial/errors.rst +++ b/Doc/tutorial/errors.rst @@ -131,7 +131,7 @@ the exception (allowing a caller to handle the exception as well):: f = open('myfile.txt') s = f.readline() i = int(s.strip()) - except IOError, (errno, strerror): + except IOError as (errno, strerror): print "I/O error(%s): %s" % (errno, strerror) except ValueError: print "Could not convert data to an integer." @@ -176,7 +176,7 @@ desired. :: >>> try: ... raise Exception('spam', 'eggs') - ... except Exception, inst: + ... except Exception as inst: ... print type(inst) # the exception instance ... print inst.args # arguments stored in .args ... print inst # __str__ allows args to printed directly @@ -202,7 +202,7 @@ indirectly) in the try clause. For example:: ... >>> try: ... this_fails() - ... except ZeroDivisionError, detail: + ... except ZeroDivisionError as detail: ... print 'Handling run-time error:', detail ... Handling run-time error: integer division or modulo by zero @@ -259,7 +259,7 @@ directly or indirectly. For example:: ... >>> try: ... raise MyError(2*2) - ... except MyError, e: + ... except MyError as e: ... print 'My exception occurred, value:', e.value ... My exception occurred, value: 4 |