catching object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Igor V. Rafienko

    catching object


    Hi,


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

    h[1] >>import inspect
    h[1] >>inspect.getmr o(ValueError)
    (<type 'exceptions.Val ueError'>, <type 'exceptions.Sta ndardError'>,
    <type 'exceptions.Exc eption'>, <type 'exceptions.Bas eException'>,
    <type 'object'>)
    h[2] >>try:
    raise ValueError("arg h")
    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 "compatibil ity" (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-Dahigorr: for få parenteser
    <+Kaptein-Dahigorr: parenteser virker som lubrication under iterasjon
    <+Kaptein-Dahigorr: velkjent
Working...