How are exceptions actually implemented in assembly?

Hung Jung Lu hungjunglu at yahoo.com
Wed Jan 23 11:25:15 EST 2002


In various recent threads, I have read about exceptions. I use
exception handling on a daily basis, but never actually know how it is
implemented internally.

At microprocessor level, you basically have two ways of flow control: 

(1) goto statements: this is how subroutines/functions are
implemented, with pushing and popping of stacks.

(2) interrupts: actual microprocessor interruptions. You jump to
another address when something "bad" or "urgent" happens.

So, how is C (hence Python) exception handling actually implemented? I
searched the web without hitting answers. My guess is that it is
choice (1), with a call to a sub-block of code having one extra item
in the return stack. If so, is exception handling actually kind of
resource-intensive? (extra codes, extra memory that propagate down the
code block structure?) Or are exceptions implemented in some smart way
that doesn't drain too much resources? Just curious.

(This is related to the Aspect thread... exception handling being
often mentioned as an "aspect", but I have not seen any code example
in Aspect Oriented Programming that actually implements exception
handling as an aspect.)

thanks,

Hung Jung



More information about the Python-list mailing list