If the exception was caused by a system call, the operating system performs the service requested by the user program, e.g., writing a character to the console, or opening a file. If the program performed an illegal operation, the operating system must decide what to do, e.g., it may simply terminate a user program that tries to divide by zero. You will need to improve this exception handler so that it handles all of the other possible exceptions. The operating system indicates that it has finished handling the exception by returning from its exception handling function. This returns control to the machine simulation, which once again begins fetching and executing user program instructions.
Interrupts are very similar to exceptions.
However, they are not caused by instructions executed by the running user program. For example, the simulated console generates an interrupt whenever a new input character is available from the keyboard. Each time it finishes executing a user program instruction, the hardware simulation checks whether one of these devices is ready to cause an interrupt. If so, the hardware simulation invokes an operating system interrupt handling function instead of executing the next user program instruction. Like an exception handler, an interrupt handler is an operating system function.