How are exceptions actually implemented in assembly?

Martin von Loewis loewis at
Thu Jan 24 06:58:10 EST 2002

"hungjunglu" <hungjunglu at> writes:

> So, exception handling indeed uses propagation of calling stacks all 
> the way down to the smallest code blocks. Hence, bloating up code 
> size, and slow down execution speed.

It much depends on the compiler. A smart compiler, such as GCC, avoids
run-time overhead for exception handling if no exception ever occurs.

> Exception handling then indeed is also an "aspect", then. (a) Before 
> executing the block (this is the "before advice"): it puts an extra 
> item in the calling stack, so if there is an exception, the code 
> block can assign a value to this stack item. 

This is how MSVC does it. With gcc (and many other compilers), the
compiler generates tables of exception regions which are not
considered until stack unwinding starts.


More information about the Python-list mailing list