Exceptions' Behaviour

Quinn Dunkan quinn at yak.ugcs.caltech.edu
Thu Jul 26 13:59:15 EDT 2001


On 19 Jul 2001 11:06:02 -0700, Tom Good <Tom_Good1 at excite.com> wrote:
>Martin Sj?ren <martin at strakt.com> wrote in message news:<mailman.995526636.21726.python-list at python.org>...
>> Yes I know that, but that's not what I'm asking. What I'm asking is why i
>> n
>> 
>> >>> raise ("a","b")
>> 
>> the "b" disappears? IMO that's a pretty weird behaviour. Yes anybody usin
>> g
>> non-class exceptions derived from Exception in a real-world program are
>> insane, but this is a puristic thing of mine. :-)
>> 
>> Martin
>
>I agree, it is kind of weird, and I don't know why it works that way. 
>I would probably expect trying to raise a tuple to generate an error.

I expect it's backwards compatibility.  Many moons ago there were no
user-defined classes, and hence no instance exceptions.  Ever notice the
__getitem__ trickiness IOError does so it can be unpacked like like a 2-tuple?
I have a feeling that once upon a time it was.

Try starting python with -x and notice that the 'b' no longer disappears.

Instance exceptions are probably an example of a past major change which could
have broken a lot of code.  It seems to have been handled quite well, which is
good, because there is code using -x and string exceptions to this day.  It
has left a couple little warts behind, but you can't please everyone.  The
trick is balancing compatibility against acquiring warts.



More information about the Python-list mailing list