Python-list Digest, Vol 76, Issue 303

siddhartha veedaluru siddhartha.veedaluru at gmail.com
Fri Jan 29 04:17:56 EST 2010


Hi,

Thats the output i got in output window.it is not listing the statement
which caused it. copy paste and try it on you setup. it behaves the same
way.

I know that error is in log.info() function call.but it is not caught by
"except". which is not getting logged using log.exception

Thanks
Siddhartha


---------- Forwarded message ----------
From: Steve Holden <steve at holdenweb.com>
To:
Date: Tue, 26 Jan 2010 11:54:23 -0500
Subject: Re: TypeError not caught by except statement
siddhartha veedaluru wrote:
> Hi,
>
> except not able to caught the TypeError exception occured in the below
> code
>
>        log.info <http://log.info>("refer",ret<http://log.info%3e(%22refer%22,ret/>)
in the try block
>
> throws a TypeError which is not caught .

The traceback you provide does not show the line in question, so I am
confused as to why you would think it was causing the problem. The
purpose of the traceback is to show you where the exception occurred,
and I question whether that is happening here.

Anyway, I suspect your error might go away if you turned the first
argument of hte log.info() call into a format string such as

 log.info("refer: %s", ret)

regards
 Steve

> Also sometimes process is getting hanged.
>
>
------------------------------------------------------------------------------------------------------------------------------------------------
> import logging
> log = logging.getLogger()
> fileName = strftime("%d-%b-%Y-", gmtime()) + str(int(time.time())) + "-
> Log.log"
> log = logging.getLogger()
> log.setLevel(logging.NOTSET)
> fh = logging.FileHandler(logFile)
> logFileLevel = logging.DEBUG
> fh.setLevel(logFileLevel)
> format_string = '%(process)d %(thread)d %(asctime)-15s %(levelname)-5s
> at %(filename)-15s in %(funcName)-10s at line %(lineno)-3d "%(message)
> s"'
> fh.setFormatter(logging.Formatter(format_string))
> log.addHandler(fh)
>
> try:
>    log.info <http://log.info>("start <http://log.info%3e(%22start/>")
>    log.info <http://log.info>("refer",ret<http://log.info%3e(%22refer%22,ret/>
)
>    log.info <http://log.info>("end <http://log.info%3e(%22end/>")
> except TypeError:
>    log.exception("Exception raised")
>
>
----------------------------------------------------------------------------------------------------------------------------------------------
> OUTPUT message:
>
> Traceback (most recent call last):
>  File "C:\Python26\lib\logging\__init__.py", line 768, in emit
>    msg = self.format(record)
>  File "C:\Python26\lib\logging\__init__.py", line 648, in format
>    return fmt.format(record)
>  File "C:\Python26\lib\logging\__init__.py", line 436, in format
>    record.message = record.getMessage()
>  File "C:\Python26\lib\logging\__init__.py", line 306, in getMessage
>    msg = msg % self.args
> TypeError: not all arguments converted during string formatting
>


--
Steve Holden           +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC                 http://www.holdenweb.com/
UPCOMING EVENTS:        http://holdenweb.eventbrite.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100129/5dcc2823/attachment.html>


More information about the Python-list mailing list