Special software is written to handle these interrupts. There are other conditions that also require the CPU to execute special code. There are two basic types of exceptions. The user program cannot continue until whatever caused the trap is dealt with. If the program was re-run with the same input, a trap would occur in precisely the same place in the code.
Exception handling The mechanism for dealing with exceptions is simple.
After the handler is finished doing whatever it needs to, the hardware returns control to the user program. Therefore, the exception handler can't change registers values or the system stack. Actually, it can use registers and the system stack, it just has to save the previous contents first and then restore those contents before it returns. This is just like a procedure saving s-registers before using them and restoring them after they're done being used. The handler often uses the system stack to temporarily store register values.