An exception is an unexpected event that occurs within the processor, while an interrupt is an unexpected event from outside the processor. When an exception or interrupt occurs, the hardware executes interrupt handler code in the operating system kernel to handle the event. This may involve killing processes, outputting errors, or communicating with devices. The handler saves the context of the interrupted process, determines the cause, handles the event, then restores the context and resumes execution of either the original or another process.