How are exceptions actually implemented in assembly?
Steven Majewski
sdm7g at Virginia.EDU
Wed Jan 23 17:24:48 EST 2002
On 23 Jan 2002, Aahz Maruch wrote:
> Note carefully that the cost comes almost entirely during the handling
> of exceptions, not in setting up exception blocks. So if as a
> percentage of instructions executing exceptions are rare, it's a very
> small penalty.
And that is the sense I've always thought of the term 'exception' -- i.e.
that it's the exceptional case that happens infrequently (relative
to the other cases). Most loops have a lot of repetitions but a
single exit. (And python builds up an exception block for 'for' loops
and uses an exception to exit the loop.) Tim, I think, was responsible
for the idiom (before there were defaults for dictionary .get()'s ):
try: return dict[key]
except KeyError: return default
which, if missing keys are a relatively rare case, was more effecient
than testing if dict.has_key(key) for every access.
I don't think the problem is the term 'exception' so much as it is
that folks seem to think that they should use the same rules in
Python as they do in C++ or Java.
-- Steve
More information about the Python-list
mailing list