How to handle exceptions properly in a pythonic way?
zljubisic at gmail.com
zljubisic at gmail.com
Mon Nov 9 16:36:47 EST 2015
Hi,
You are right. I am trying to address a few questions at the same time.
As English is not my first language, I can only say that you have addressed them very well. Thanks.
1. Where to put the try/except block, inside or outside the function
2. How to deal with un-anticipated exceptions
3. How to keep record
1. If try/except block is outside the function, I have to always put function call in try/except block, even for logging. From my point of view, I could put at least logging in the function and then re raise the error.
2. I have just read what TDD is. I should write my first unit test to get a grip. Anyway, I have a program in which I am looping through several of records. If something happens I would like to put the warning in the log. In that case I need to put for loop in try/except Exception as e: block in order to log an unknown exception
3. For me, logging is necessary. Every script (only few of them) I have done, has a underlying log.
Thanks.
Regards.
More information about the Python-list
mailing list