[Python-ideas] Add "goto fail" to Python?

Sturla Molden sturla.molden at gmail.com
Thu Mar 6 04:54:24 CET 2014


"goto fail" is a well-known error handling mechanism in open source 
software, widely reputed for its robusteness:

http://opensource.apple.com/source/Security/Security-55471/libsecurity_ssl/lib/sslKeyExchange.c

https://www.gitorious.org/gnutls/gnutls/source/6aa26f78150ccbdf0aec1878a41c17c41d358a3b:lib/x509/verify.c

I believe Python needs to add support for this superior paradigm.

It would involve a new keyword "fail" and some means of goto'ing to it. 
I suggest "raise to fail":

if (some_error):
    raise to fail

fail:
    <error handling code>

Unless there are many objections, this fantastic idea might be submitted 
in a (short) PEP somewhere around the beginning of next month.

There is some obvious overlap with the rejected "goto PEP" (PEP 3163) 
and the Python 2.3 goto module. However, the superiority of goto fail as 
error generation and error handling paradigm has since then been 
thoroughly proven.

http://legacy.python.org/dev/peps/pep-3136/
http://entrian.com/goto/download.html


Regards,
Sturla Molden









More information about the Python-ideas mailing list