why logging re-raise my exception and can't be caught?

Ben Finney bignose+hates-spam at benfinney.id.au
Sun Oct 1 06:20:57 EDT 2006


Steve Holden <steve at holdenweb.com> writes:

> Ben Finney wrote:
> [...]
> > A 'try ... except' statement is not an exception handler. [...]
>
> Just as a matter of interest, what would your definition of an
> exception handler be, then? Specifically, what's the "except" clause
> for?

It seems my understanding was wrong. The 'except' clause *is* an
exception handler. (I was thinking that the "default exception
handler" was the only thing that could be called an "exception
handler".) It's explained better here:

    <URL:http://docs.python.org/ref/try.html>

> The docs for looging.except should make it explicit that the
> exception will be re-raised.

Yes, I agree; it wasn't very clear on reading the description of
'logging.exception()' what would actually happen.

> Of course it might be possible to do something hackish like
>
>      try:
>          ...
>      except:
>          try:
>              logging.exception(...)
>          except:
>              pass
>
> which (although untested) should theoretically allow the catching
> (for a second time) of teh exception reraised by
> logging.exception().

It does seem rather a side effect, and an unexpected (and
undocumented) one at that.

-- 
 \        "If it ain't bust don't fix it is a very sound principle and |
  `\      remains so despite the fact that I have slavishly ignored it |
_o__)                                  all my life."  -- Douglas Adams |
Ben Finney




More information about the Python-list mailing list