[Python-Dev] why string exceptions are bad
Jewett, Jim J
jim.jewett at eds.com
Fri Mar 19 17:30:50 EST 2004
>> Out of curiosity, why are string exceptions going away?
> Probably, originally, for many of the reasons stated here.
> That people expected equality tests in the except clause
> and were tripped up by the identity test performed.
Trying to catch (some, but not all) exceptions from another
module can be difficult if the module raises strings. At
best, you catch everything, test with == (even though "is"
seemed to work in your tests), and maybe reraise.
If they start raising
"Error: You requested 7 but the quota is 6"
you have to regex match.
If the "same" error is raised several places (or by several
different modules), there will eventually be a typo.
"Error: That was not a string"
"Error: That was not a string."
"Error: That was mot a string."
"Error That was not a string."
"Error: That wasn't a string"
"ERROR: That was not a string"
A class can be defined in a single place (and imported);
a typo in the 47th raise statement will show up as a syntax
error instead of a runtime bug.
More information about the Python-Dev