Wording suggestion for documentation (Data Model)

J

Jason R. Coombs

#!python

"""
In the documentation for __del__ (under Python Language Reference/Data
Model), the following warning is indicated:

Warning [Caveat in 2.6]: Due to the precarious circumstances under
which __del__() methods are invoked, exceptions that occur during
their execution are ignored, and a warning is printed to sys.stderr
instead. ...

That statement appears, however, to be incorrect.

Perhaps the warning should be re-worded to say "When __del__() methods
are invoked, exceptions that occur during the execution of such
methods must be caught and handled within the scope of the __del__()
method call. Otherwise unhandled exceptions will be ignored except
for a warning printed to sys.stderr instead."

For example,
"""

class X(object):
def __del__(self):
print 'deleting', self
try:
raise Exception, "OMG!"
except:
print 'caught exception, np'
print 'made it past the exception'

x = X()
del x

print 'x has been deleted, now what?'

"""
All this prints something like:

deleting <__main__.X object at 0x01BB1A50>
caught exception, np
made it past the exception
x has been deleted, now what?
"""

# - Jason R. Coombs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top