Exception as the primary error handling mechanism?

Mel mwilson at the-wire.com
Fri Jan 1 17:06:21 CET 2010


Steven D'Aprano wrote:

> On Fri, 01 Jan 2010 02:43:21 -0800, Jonathan Gardner wrote:
> 
>> On Jan 1, 12:43 am, a... at pythoncraft.com (Aahz) wrote:
>>> In article <mailman.300.1262323578.28905.python-l... at python.org>,
>>> Benjamin Kaplan  <benjamin.kap... at case.edu> wrote:
>>> >In Python, throwing exceptions for expected outcomes is considered
>>> >very bad form [...]
>>>
>>> Who says that?  I certainly don't.
>> 
>> Agreed.
>> 
>> int("asdf") is supposed to return what, exactly? Any language that tries
>> to return an int is horribly broken.
> 
> 
> [sarcasm]
> No no, the right way to deal with that is have int("asdf") return some
> arbitrary bit pattern, and expect the user to check a global variable to
> see whether the function returned a valid result or not. That's much
> better than catching an exception!
> [/sarcasm]

Or the other way around, as in C (I suspect the original ACM article assumed 
C.)  Look at the legion of C library subroutines that return only 0 for good 
or -1 for bad, and do all their real work in side-effects (through pointers 
as function arguments.)  Python is a big improvement: use the function 
return values for the payload, and push the out-of-band "omyghod" response 
into an Exception.

	Mel.





More information about the Python-list mailing list