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

skip@pobox.com skip at pobox.com
Thu Aug 25 22:45:00 CEST 2005

    MAL> I must have missed this one:

That's because it was brief and to the point, so the discussion lasted for
maybe three messages.  Also, someone told us you were on holiday so we
thought we could squeak it through without you noticing.  Darn those
Aussies.  Late on the pydev summary again! <wink>

    >> ----------------------------
    >> 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.

I do have a followup question on the style thing.  (I'll leave others to
answer MAL's question about optimization.)  If I want to raise an exception
without an argument, which of the following is the proper form?

    raise ValueError
    raise ValueError()


More information about the Python-Dev mailing list