Search code examples
interruptinterrupt-handling

What does an interrupt handler do?


I know that when a keyboard interrupt occurs, the handler has code to save the character that has been received. What about other events that create interrupts like stack overflows, arithmetic overflow, divide by zero, etc? What does the interrupt handler do when these events occur?


Solution

  • There are basicaly three types of interrupts:

    • Hardware interrupts happen when there is a signal from an external device, like for example the keyboard or a mouse. The interrupt handler for those will get the data from the device and then let the program continue as if nothing happened.

    • Software interrupts are triggered by the program itself, they are used to call subroutines in the operating system or in device drivers.

    • Exception interrupts are triggered by certain operations when there is an unexpected result or a condition where there can't be a normal result, for example a division by zero. What the handlers for those do differ a bit depending on what the error is, but generally they print out an error message and terminate the program.