Exception-handling

O

Odd-R.

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?

Thanks!
 
D

Diez B. Roggisch

Odd-R. said:
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
 
R

Rene Pijlman

Odd-R.:
I thought Exception would catch all exceptions.

Try this:

import sys

try:
pass # your code here
except:
e = sys.exc_value()

Either to catch everything, or to get a hold on e.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,052
Latest member
KetoBeez

Latest Threads

Top