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

Ben Finney bignose+hates-spam at benfinney.id.au
Sat Sep 30 03:46:55 EDT 2006


"daniel" <daniel.huangfei at gmail.com> writes:

> I'm expecting the exception to be caught silently, and print the msg to
> some place

Then why not use logging.error() ?

<URL:http://docs.python.org/lib/module-logging>
=====
error(msg[, *args[, **kwargs]])
    Logs a message with level ERROR on the root logger. The arguments
    are interpreted as for debug().

exception(msg[, *args])
    Logs a message with level ERROR on the root logger. The arguments
    are interpreted as for debug(). Exception info is added to the
    logging message. This function should only be called from an
    exception handler.
=====

A 'try ... except' statement is not an exception handler. So, if you
want to log the fact that an error occurred, it seems logging.error()
is the correct choice.

-- 
 \        "I have one rule to live by: Don't make it worse."  -- Hazel |
  `\                                                          Woodcock |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list