Well, there USED to be an easy ( but not-documented, so not obvious )
way - the sys module contained the objects sys.exc_type & sys.exc_value,
so I used to be able to:
try:
<dangerous code>
except:
print my_msg
raise sys.exc_type,sys.exc_value
This WAS an undocumented feature, but it seems to have disappeared ( or
moved ? ). "import sys; dir(sys)" no longer shows exc_type & exc_value.
I was at first quite distressed to discover that this feature was now
missing. I know I'm looking for trouble relying on an undocumented
feature ... I don't mean I'm distressed because I have to change my
code. If it were moved and renamed, I wouldn't complain. [ As is is,
I'm trying to keep my complaint muted, because although I like the
functionality of the feature, I must admit it is sort of a kludge. It
might be better to have the exception be locally assignable as the
optional argument is, not a "global" symbol in module sys. ]
But now, it is quite awkward to write exception handlers that have
common code for several exceptions. (minor). AND I don't see any way
to write a generic exception handler that re-raises some of all of its
exceptions to an outer handler. (major). One has to make an exhaustive
list of exceptions, and any new ones not on the list will not be caught.
I see there are some notes about changes to error handling in error.c.
I assume that this change ( disappearance of sys.exc_type ) is related
to the changes in that code. (?)
My first impression is that I don't like this.
[ I admit I'm biased by growing up on VAX/VMS error handling, which
are a bit more "full featured" than vanilla C/UNIX signals. ]
- Steve
[ Sorry Tim, but your kludge around it looks even uglier! :-( ]