[newbie] Confused with raise w/o args

Fredrik Lundh fredrik at pythonware.com
Mon Feb 14 08:15:59 EST 2005


"jfj" <jfj at freemail.gr> wrote:

> Wait! second that. We would like to

hmm.  are you seconding yourself, and refering to you and yourself as we?

> here is another confusing case:
>
> ###################
> import sys
>
> class A:
>  pass
>
> class B:
>  pass
>
> def foo ():
>     try:
> raise B
>     except:
> pass
>     raise
>
> def b1():
>  try:
>    raise A
>  except:
>    foo()
>
> try:
>     b1 ()
> except:
>     print sys.exc_info()[0]
> ##################
>
> This reports that __main__.B is raised but wouldn't it be better
> to raise an 'A' since this is the currently handled exception?

no.  your foo() function raises B, and is called from the exception
handler in b1.  exception handlers are free to raise new exceptions
at any time.

maybe you should take a deep breath, and try to figure out exactly
what's confusing to you before posting more examples.

(btw, using traceback.print_exc() instead of print sys.exc_info may
give you more clues about what's really going on.)

</F> 






More information about the Python-list mailing list