Where to put the error handing test?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Nov 24 13:33:18 CET 2009


On Mon, 23 Nov 2009 21:15:48 -0600, Peng Yu wrote:

> Suppose that I have function f() that calls g(), I can put a test on the
> argument 'x' in either g() or f(). I'm wondering what is the common
> practice.
> 
> My thought is that if I put the test in g(x), the code of g(x) is safer,
> but the test is not necessary when g() is called by h().

If the function g requires the test, then put it in g. If it does not 
require the test, then don't put it in g.

If the test is only required by f, then it belongs in f.



-- 
Steven



More information about the Python-list mailing list