A translating software emulator designed for converting code from a legacy
system to a target system and fully preserving the synchronous exception
state while still allowing for full and aggressive optimization in the
translation. A user application is translated to a target system using
full optimization techniques. The translation may be done dynamically by
an emulator emulating the legacy system on the target system, or the
translation may be a static translation or a compilation, fully generating
a new executable program operable on the target system. The invention
recovers from the exception properly by restoring the target machine state
to the machine state expected by the legacy system. This recovery is done
by using an exception delivery mechanism to restore the machine state of
the target system before executing the exception handling code. The
restoration of the machine state is done by executing a recovery block
generated by the translation that modifies the machine state to match the
legacy machine state.