D
D
Dmitry2012-03-16 12:12:10
Python
Dmitry, 2012-03-16 12:12:10

How should exceptions be handled if an "exception chain" occurs?

Please help/teach how to write exception handling code in Python 3.2.

Listing #9 here: Getting Started with Python 3: Part 2 More Advanced Topics has an example of an "exception chain".

I want to understand how to write exception handling code to prevent such chains?

I have the following situation:
1) In the self._executeTestCase() function I call the md5_of_file() function in the code of which open is called with the wrong input file name ".../pe.sdfasdf/???" which quite rightly flies IOError with Invalid parameter
2) The md5_of_file() call itself in the self._executeTestCase() code is framed in a try-except block, EnvironementError is caught in except, e.args[1] is written to the log and my type ExecuteTestCaseError is thrown
3) The self._executeTestCase() method is called in a loop inside the self._executeTestPlan() method and is framed in a try-except, with two exept branches. In the first one, ExecuteTestCaseError is caught, and in the second, BaseException Is

everything correct?

PS: Please do not kick the newbie, I'm still reading Lutz and these are the first steps in mastering the python)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2012-03-16
@EvilsInterrupt

The question is settled, due to inattention, I made a logging error in the except-block, and the logger object was received in the try-block.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question