Exception confusion

Martin Sjögren martin at strakt.com
Wed Aug 8 06:04:12 EDT 2001


I wrote this little test script:

try: raise Exception, "foo"
except Exception, arg: print type(arg)

And it said <type 'instance'> (i.e. the exception object)
When I tried this:

try: raise Exception, "foo"
except Exception, (arg,): print type(arg)

It said <type 'string'>.
Happy with that, I tried to raise a tuple instead:

try: raise Exception, ("foo", "bar"):
except Exception, (arg,): print type(arg)

and it said "ValueError: unpack sequence of wrong size".

try: raise Exception, ("foo", "bar"):
except Exception, arg: print type(arg)

still says that arg is an instance. So I manually have to do:

try: raise Exception, ("foo", "bar"):
except Exception, (arg1,arg2): print type(arg1), type(arg2)

which says that both arg1 and arg2 are strings.


Doesn't this strike anybody as inconsequent?


Here's another interesting thing:

try: raise Exception, ["foo"]
except Exception, arg: print arg[0]

says  ['foo']  while

try: raise Exception, ["foo"]
except Exception, (arg,): print arg[0]

says  foo.


So the exception object IS subscriptable, but it doesn't do anything??


Anybody have any comments, 'cause I'm confused... Does any of this warrant
a bug report?


And-I-thought-exceptions-were-confusing-before-this-ly y'rs - Martin

-- 
Martin Sjögren
  martin at strakt.com              ICQ : 41245059
  Phone: +46 (0)31 405242        Cell: +46 (0)739 169191
  GPG key: http://www.strakt.com/~martin/gpg.html




More information about the Python-list mailing list