From: bob on
Let's say an exception gets thrown in C++. How does this typically

translate into assembly language?
From: robertwessel2 on
On Jan 17, 9:36 pm, b...(a)coolgroups.com wrote:
> Let's say an exception gets thrown in C++. How does this typically
>
> translate into assembly language?


The details vary considerably, but basically the compiler has to
generate code to do several things:

1. Track all nested frames. That usually invokes a linked list
running up the stack, and includes nested scopes as well. This needs
to include enough information to restore registers and stack points as
appropriate.

2. For each nested frame, generate code to call all destructors for
all locally created objects.

3. For each nested frame, generate code to execute the catch block, if
it exists.

4. For each nested frame, generate code to match the exception to each
catch condition. If you get a match, execute the appropriate catch
block, otherwise run the destructors, and bump a level up the chain,
and repeat.

5. The throw itself is a minor modification of #4.

6. There needs to be code to handle an exception that never hits a
catch, usually by printing a message and terminating the program.

That's usually a fair bit of overhead for each function invocation, so
exception handling is turned off by default in many compilers.
From: Phil Carmody on
bob(a)coolgroups.com writes:
> Let's say an exception gets thrown in C++. How does this typically
>
> translate into assembly language?

In a similar way to a call/return stack, except that all the
housekeeping has to be done explicitly, and you don't know
in advance how far the equivalent of a return (throwing an
exception) is going to rewind, you need to check if it can be
caught at each level.

Phil
--
Dear aunt, let's set so double the killer delete select all.
-- Microsoft voice recognition live demonstration
 | 
Pages: 1
Prev: cmovcc
Next: FPU multiplication issue