This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jaraco
Recipients alexandre.vassalotti, belopolsky, brett.cannon, ehuss, facundobatista, georg.brandl, gvanrossum, jafo, jaraco, jarpa, kylev, loewis, nnorwitz, tseaver, zseil
Date 2010-09-22.14:58:04
SpamBayes Score 0.0012687591
Marked as misclassified No
Message-id <1285167487.24.0.799498618025.issue1692335@psf.upfronthosting.co.za>
In-reply-to
Content
After some further reading, I found that PEP-352 (http://www.python.org/dev/peps/pep-0352/) explicitly states that "Including programmatic information (e.g., an error code number) should be stored as a separate attribute in a subclass [and not in the args attribute]." The parameter to Exception.__init__ should always be a single, human-readable string. The default pickler doesn't handle this officially-prescribed use-case without overriding __reduce__.

class F(Exception):
    def __init__(self, message, code):
        Exception.__init__(self, message)
        self.code = code

Of course, as belopolsky observed, __repr__ must also be overridden.
History
Date User Action Args
2010-09-22 14:58:07jaracosetrecipients: + jaraco, gvanrossum, loewis, nnorwitz, brett.cannon, georg.brandl, facundobatista, jafo, ehuss, tseaver, belopolsky, zseil, alexandre.vassalotti, jarpa, kylev
2010-09-22 14:58:07jaracosetmessageid: <1285167487.24.0.799498618025.issue1692335@psf.upfronthosting.co.za>
2010-09-22 14:58:05jaracolinkissue1692335 messages
2010-09-22 14:58:04jaracocreate