Exceptions' Behaviour

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Jul 19 04:14:52 EDT 2001


Martin Sjögren <martin at strakt.com> wrote in 
news:mailman.995459309.19355.python-list at python.org:

> What's going on here? If (A, B) is raised like A, B, why don't I get
> anything in my 'var' variable? If not, how come (A, B) is matched against
> A?

raise takes 0 to 3 expressions. (A, B) is a single expression yielding a 
tuple. You could have written 'raise (A, B), "Hello"' and then var would 
have been set to "Hello". However, a tuple isn't a valid type for an 
exception which must be a string class or instance object so I think that 
probably this should have thrown a TypeError as it does if you try to 
'raise 3'. Why it didn't escapes me, but a quick play with the interpreter 
seems to indicate that raising any tuple is equivalent to raising the first 
element of the tuple and the remaining elements are lost.

I just looked at the source and in fact it is recursive, as long as the 
first argument is a tuple, it replaces it with its first element.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list