Exception-handling
Diez B. Roggisch
deets at nospam.web.de
Fri Feb 24 05:01:42 EST 2006
Odd-R. wrote:
> I have come over a strange problem regarding exceptions
> This is my code:
>
> try:
> #some operation
> except Exception, info:
> #some message
> except:
> #??
>
> When executing my code, I get to the last block here. This
> I find rather strange, because I thought Exception would catch
> all exceptions. But this is obviously not the case here.
>
> What is this, and how can I get a hold of what causes the exception?
You can throw everything as an exception. I _think_ that is frowned upon
these days, but it is there so it will happen.
However, you can use
import sys
try:
raise "foo"
except:
print sys.exc_info()[1]
to get a hold on what's being caught by the exception handler.
Diez
More information about the Python-list
mailing list