By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,035 Members | 1,408 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,035 IT Pros & Developers. It's quick & easy.

catching object

P: n/a

I was wondering if someone could help me explain this situation:

h[1] >>import inspect
h[1] >>inspect.getmro(ValueError)
(<type 'exceptions.ValueError'>, <type 'exceptions.StandardError'>,
<type 'exceptions.Exception'>, <type 'exceptions.BaseException'>,
<type 'object'>)
h[2] >>try:
raise ValueError("argh")
except object:
print "why not?"

Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ValueError: argh

The question is, why isn't ValueError caught? It *does* inherit from
object (albeit indirectly), and my understanding of the wording of
CPython docs is that this guarantees "compatibility" (between what is
being raised and what is being caught).

So, why doesn't object match ValueError (or any other exception for
that matter). I am aware of "except:", but in my particular situation
it is eh... unsuitable.

Any hints/pointers are appreciated.

<+Kaptein-Dahigorr: for få parenteser
<+Kaptein-Dahigorr: parenteser virker som lubrication under iterasjon
<+Kaptein-Dahigorr: velkjent
Mar 12 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.