[Python-Dev] Style for raising exceptions (python-dev Summary for 2005-08-01 through 2005-08-15 [draft])

M.-A. Lemburg mal at egenix.com
Thu Aug 25 11:35:59 CEST 2005


I must have missed this one:

> ----------------------------
> Style for raising exceptions
> ----------------------------
> 
> Guido explained that these days exceptions should always be raised as::
> 
>     raise SomeException("some argument")
> 
> instead of::
> 
>     raise SomeException, "some argument"
> 
> The second will go away in Python 3.0, and is only present now for backwards
> compatibility.  (It was  necessary when strings could be exceptions, in
> order to pass both the exception "type" and message.)   PEPs 8_ and 3000_
> were accordingly updated.

AFAIR, the second form was also meant to be able to defer
the instantiation of the exception class until really
needed in order to reduce the overhead related to raising
exceptions in Python.

However, that optimization never made it into the implementation,
I guess.

> .. _8: http://www.python.org/peps/pep-0008.html
> .. _3000: http://www.python.org/peps/pep-3000.html
> 
> Contributing threads:
> 
> - `PEP 8: exception style
> <http://mail.python.org/pipermail/python-dev/2005-August/055187.html>`__
> - `FW: PEP 8: exception style
> <http://mail.python.org/pipermail/python-dev/2005-August/055191.html>`__

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Aug 25 2005)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::


More information about the Python-Dev mailing list