Python Exceptions

Alex Kowalenko (alex@jolt.mpx.com.au)
6 Jan 1995 10:50:31 GMT

Why do python exceptions have to be strings, couldn't they be a object that
has a __str__ method defined returning the string wanted. If they could
be we could throw generic objects around that can contain other actions.

(This shows my C++ background)

I know that there is another message argument that you could pass another,
but why two when you could encapsulate it into one.

ie.

class Exception :

def __init__(s, exception, where = None) :
s.exception = exception
s.where = where

def __str__(s) :
return s.exception

def someAction(s) :
..

...

raise Exception(ZeroDiv, cellRef)

...

try : x() except ZeroDiv :
sys.exc_type.someAction()
...

I'm not demanding a change, it's just an idea.

Alex Kowalenko
alex@mpx.com.au