Exception as the primary error handling mechanism?
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Tue Jan 5 23:49:52 EST 2010
On Tue, 05 Jan 2010 15:51:29 -0800, Phlip wrote:
> Why can't int('nonnumeric') return None?
It could do that, but it shouldn't, because returning magic values
instead of raising exceptions is usually a bad, bad idea.
> (A related question - why can't I just go 'if record = method(): use
> (record)'. Why extra lines just to trap and assign the variable before
> using it?)
Because that idiom is responsible for probably the most common error in C
of all, at least one of the most common errors. Thank goodness Python
forbids such a dangerous construct.
--
Steven
More information about the Python-list
mailing list