Re: sys.exc_type etc

Peter Ho (peter@robots.oxford.ac.uk)
Wed, 11 Mar 92 16:57:58 GMT

I do agree with Tim that if we had
try exc_type, exc_val:
the variables would clutter try block. However, I think there usefulness
might outweigh it. I agree with the suggestion made by Steve (sorry if I
got your name wrong), that these values would have to be local, so that only
visible in that try .. except .. finally .. block. Would it be possible?

Whilst we're on this point, Guido why didn't you make the exception
value variable in 'except' local to only that exception (like modula-3)? You
would remove the problem that Tim pointed out of clobbering an exception
name. I would be happy to see an example which finds this non-locality of
the exception values useful :-).

Going back to those examples given by Tim:
> | try:
> | print kidding
> | except NameError:
> | try: 1/0
> | except:
> | print 'sys.exc_type should certainly be a zero-divide here'
> | # but what should sys.exc_type be here?
> | [tim sez NameError]
> | ...
> |
> | elist = (None, NameError)
> |
> | def absurd(i):
> | try:
> | try:
> | 1/0
> | except DivideByZeroError: # meant ZeroDivisionError
> | print 'caught an exception that doesn\'t exist!'
> | except elist[i], val:
> | print 'caught the', elist[i], 'error on', val
> |
> | absurd(2)

I am coming to the belief that in both cases the value of sys.exc_type is
correct in each case. If you have an error in your exception handler (or
before you enter the handler in the second example) then you should be told
about it. What puzzles me though is the second example, what should happen
to sys.exc_type and exception reporting from Python, what about having a
list returned in sys.exc_type?

Pete. 8-)