ask help about raise, thank u
John Machin
sjmachin at lexicon.net
Tue Feb 26 15:44:39 EST 2002
"Emile van Sebille" <emile at fenx.com> wrote in message news:<a5g41c$70hbr$1 at ID-11957.news.dfncis.de>...
> "John Machin"
> > # re-raise the exception, with traceback giving the *original*
> > # source of the problem (somewhere inside the 'try' suite),
> > # not the 'raise' statement
> > raise exc, data, tb
> >
>
> Isn't this what raise by itself does?
>
> >>> def test(d=None):
> ... try:
> ... 1/d
> ... except TypeError:
> ... return 0
> ... except:
> ... raise
> ...
> >>> test()
> 0
> >>> test(0)
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "<stdin>", line 3, in test
> ZeroDivisionError: integer division or modulo by zero
> >>>
Quite possibly. I profess ignorance -- see the disclaimer in my post.
I posted merely in case the cognoscenti ignored an unfortunate whose
post turned up (in Google Groups at least) encoded in base64.
Could you please enlighten me on the following:
If a bare 0-arg raise is (mostly) equivalent to:
x, y, z = sys.exc_info()
raise x, y, z
(apart from the circular reference problem) then what is the 3-arg
raise useful for?
The reference manual says:
"""If a third object is present, and it is not None, it should be a
traceback object (see section 3.2), and it is substituted instead of
the current location as the place where the exception occurred. This
is useful to re-raise an exception transparently in an except
clause."""
There is a very interesting 39-message thread back in April 1998 that
actually documents the conception & birth of 0-arg raise --
Google("raise traceback"). Seems like 3-arg raise is now not very
useful, and the manual could perhaps point out that 0-arg raise now
handles the "re-raise transparently" functionality.
I note that of the 4 examples of 3-arg raise in urllib.py, one seems
to have the circular reference problem.
While seeking enlightenment: What mechanism did you use to search all
of Lib/*.py for 3-arg raises?
Regards,
John
More information about the Python-list
mailing list