How much sanity checking is required for function inputs?

Stephen Hansen me at ixokai.io
Wed Apr 20 02:17:37 EDT 2016


On Tue, Apr 19, 2016, at 11:09 PM, Ethan Furman wrote:
> On 04/19/2016 10:51 PM, Stephen Hansen wrote:
> > I use 1) more to be less 'nicer' and more, er, 'more specific'. Since I
> > don't like exceptions to rise to the user level where niceness is
> > needed.
> 
> Yeah, that's a better phrasing for (1); I meant more appropriate or 
> informative, such as swapping an internal error (such as KeyError) for a 
> more meaningful FieldNotFound error (or whatever) -- largely library 
> code concerns.

Yeah, and what the OP is doing is going the exact opposite-- from a
more-specific exception (KeyError) to a more generic one (Exception).

To me that's (usually) an anti-pattern. 

--S



More information about the Python-list mailing list