catching object

Igor V. Rafienko igorr at ifi.uio.no
Tue Mar 11 20:05:06 EDT 2008


Hi,


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.





ivr
-- 
<+Kaptein-Dah> igorr: for få parenteser
<+Kaptein-Dah> igorr: parenteser virker som lubrication under iterasjon
<+Kaptein-Dah> igorr: velkjent



More information about the Python-list mailing list