[Tutor] logging question

Christian Witts cwitts at compuscan.co.za
Thu Oct 20 14:52:45 CEST 2011


On 2011/10/19 09:19 PM, Alex Hall wrote:
> Hi all,
> I have never done logging before, and I am wondering how it will
> change my script. Currently, I have something like this:
> for book in results:
>   try: checkForErrors(book)
>   except Exception, e:
>    print e
>    continue
>
> That way I see any errors in a given book, but that book is skipped
> and the loop continues. Now, though, checkForErrors() logs exceptions
> instead of raising them, so my try/except won't work, right? There is
> my question: if a method logs an exception instead of raising it, is
> that exception still raised by the logging module? Do I have to make
> checkForErrors() return something, and check for that, instead of
> using try/except or can I keep my loop how it is? TIA!
>

If you have some exception handling and want it to propagate further up 
the chain you can just raise it, for eg.

def checkForErrors(book):
     try:
         do_something_that_could_raise_exceptions()
     except Exception, e:
         log_errors(e)
         raise

for book in results:
     try:
         checkForErrors(book)
     except Exception, e:
         do_your_other_exception_handling()

-- 

Christian Witts
Python Developer

//
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111020/712f866f/attachment.html>


More information about the Tutor mailing list