scoping assertion
Michael Hudson
mwh21 at cam.ac.uk
Sun Jul 18 08:55:04 EDT 1999
Isao AKIYAMA <Isao.Akiyama at unisys.co.jp> writes:
> > I use
> > try:
> > raise None
> > except:
> > ....
>
> Wow!
>
> >>> import sys
> >>> try: raise None
> .. except: print sys.exc_info()
> ..
> (<class exceptions.TypeError at 89a4e0>, <exceptions.TypeError instance
> at 8cc17
> 0>, <traceback object at 8cc150>)
> >>>
>
> 'raise None' actually raises a TypeError ;-)
Well, it would. You can only raise strings, classes or instances as
exceptions:
Python 1.5.2+ (#2, Jul 14 1999, 00:03:34) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> raise 4
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: exceptions must be strings, classes, or instances
>>>
So Python gets the thing being raised (None), checks it's type, finds
it wanting - and raises an exception. Ho hum. I cant work out whether
that is a) trivial b) deep c) working, but by lucky accident or d)
silly or e) this post is a complete waste of time. Or all of the
above.
Cheers,
Michael
> Isao AKIYAMA
>
--
Oh, very funny. Very sar-cah-stic. http://www.ntk.net
http://www.ntk.net/doh/options.html - ho ho
More information about the Python-list
mailing list