diff Doc/tutorial/errors.rst @ 45048:250f29bab61b legacy-trunk

Demonstrate new except/as syntax.
author Raymond Hettinger <python@rcn.com>
date Wed, 30 Jan 2008 00:51:58 +0000
parents aad90ebbfb50
children 70f9a5db279c
line wrap: on
line diff
--- a/Doc/tutorial/errors.rst	Wed Jan 30 00:08:31 2008 +0000
+++ b/Doc/tutorial/errors.rst	Wed Jan 30 00:51:58 2008 +0000
@@ -131,7 +131,7 @@
        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 @@
 
    >>> 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 @@
    ... 
    >>> 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 @@
    ... 
    >>> try:
    ...     raise MyError(2*2)
-   ... except MyError, e:
+   ... except MyError as e:
    ...     print 'My exception occurred, value:', e.value
    ... 
    My exception occurred, value: 4