How are exceptions actually implemented in assembly?

Aahz Maruch aahz at panix.com
Wed Jan 23 17:06:37 EST 2002


In article <mailman.1011809616.25217.python-list at python.org>,
hungjunglu <hungjunglu at yahoo.com> wrote:
>--- In python-list at y..., Steven Majewski <sdm7g at V...> wrote:
>>
>> C doesn't really have exceptions in the language, but the equivalent
>> functionality is usually coded in C using setjmp & longjmp (which 
>are
>
>Thanks to all that have replied. I was more looking into really low 
>level implementation (i.e., single CPU instruction, one level further 
>down from setjump/longjmp. That is, all I wanted to know was whether 
>it was an interrupt or a jump), because all of a sudden I realized 
>that exception handling can have an appreciable cost in resources, 
>when routines call routines that call routines, etc. Python exception 
>handling is at much higher level, and it charges this cost at that 
>level. Not too bad, in a sense, since the underlying C code does not 
>necessarily have to propagate the exception handling all the way down 
>to assembly. But, it also means that at Python level, exception is 
>built into everywhere. That's OK, I guess... compared to other things 
>(e.g: variable name look up), exception handling is probably pretty 
>cheap in resources/performance.

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.
-- 
                      --- Aahz  <*>  (Copyright 2002 by aahz at pobox.com)

Hugs and backrubs -- I break Rule 6                 http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het Pythonista   

"I support family values -- Addams family values" --www.nancybuttons.com



More information about the Python-list mailing list