What is the difference between an interrupt and an exception?
Interview preparation resource from Gate Smashers.
An interrupt is usually an asynchronous event from external hardware, while an exception is a synchronous event caused by the current instruction or an explicit software trap.
Timers, keyboards, network devices and storage completion signals can interrupt the processor independently of the instruction being executed. The CPU saves enough state, identifies the interrupt source and runs the registered kernel handler.
Exceptions are directly related to execution: examples include divide-by-zero, invalid opcodes, page faults and system-call traps. Some are recoverable and allow the instruction to restart, while others cause a signal or process termination. Both use controlled CPU entry mechanisms, but their sources and timing differ.
A timer interrupt can arrive between instructions regardless of the current program, while a divide-by-zero exception is caused by the instruction being executed. In both cases the CPU saves controlled state and transfers execution to an appropriate kernel handler.
