Difference Between Similar Terms and Objects

Difference Between Interrupt and Exception

Interrupt and exception are two different concepts but they are similar in a sense that they both cause the CPU to put a stop to the normal flow of execution of instructions in order to execute another program in the kernel space to handle them. The key difference is how they handle the unexpected events that occur somewhere in the system, the processor, or within the program itself.

Interrupt

Interrupt is a signal sent to the CPU from external devices attached to the computer or a program from within the system that requires the OS to intervene in the ongoing process. Interrupts, as the name suggest, are abrupt events that put the normal flow of execution of instructions to a halt. It prompts the OS to take immediate action on what to do next. These unexpected events are usually related to an I/O device, which mostly deals with the outside world. For example, when you press a key on the keyboard or move the mouse, it triggers hardware interrupts which cause the CPU to read the keystroke or the mouse movement. So, when an interrupt occurs, the CPU runs a special ‘interrupt handling routine’ or ‘Interrupt Handler’ to take care of the event which caused it in the first place. The control is transferred to the OS as soon as an interrupt occurs, prompting it to take immediate action. Interrupts are prioritized meaning interrupts with high priority need immediate attention and have to be handled first.

Exception

The term exception is short for exceptional event and refers to unexpected events that exist somewhere in the system, the processor, or within a program that requires attention of the CPU. Exceptions, like interrupts, disrupt the normal flow of instructions but occur during program execution that are exceptional and that cannot be handled within the program itself. For example, if you command the processor to divide a number by zero, it will give a divide-by-zero exception, causing the computer to halt the calculation or display an error message. When an exception occurs, the CPU interrupts the ongoing process and immediately responds to the exception by calling a specific exception handler function, depending on the type of execution. Exceptions can be generally classified as processor-detected exceptions and programmed exceptions. The former occurs when the CPU detects any kind of anomaly while executing an instruction, while the latter is generated upon the request of the programmer.

Difference between Interrupt and Exception

Definition 

– Interrupts, as the name suggest are unexpected events that put the normal flow of execution of instructions to a halt, altering the sequence of instructions executed by a processor. The control is transferred to the OS as soon as an interrupt occurs, prompting it to take immediate action. Exceptions, on the other hand, are exceptional events that disrupt the normal flow of instructions but occur during program execution that are exceptional and that cannot be handled within the program itself. The information about the exception including its source and its type is stored in an object called exceptional object.

Source

 – When a key is pressed on a keyboard or the mouse is moved, it triggers hardware interrupts which prompt the CPU to read to keystroke or mouse movement. Software interrupts may be triggered by program execution errors, and are often called exceptions. Exceptions are generated somewhere in the system, the processor, or within a program that requires attention of the CPU. For example, if you command the processor to divide a number by zero, it will give a divide-by-zero exception, causing the computer to halt the calculation or display an error message.

Type 

– Interrupts can be generally classified as synchronous and asynchronous interrupts. Synchronous interrupts are triggered every time an instruction is executed by the CPU and are called synchronous because the CPU issues them only after terminating the execution of the instruction. Asynchronous interrupts occur when an external anomaly interrupts the processor. Exceptions can be generally classified as processor-detected exceptions and programmed exceptions. The former occurs when the CPU detects any kind of anomaly while executing an instruction, while the latter is generated upon the request of the programmer.

Handling 

– Interrupt is a class of exception, and exception is divided mainly into four classes: interrupt, fault, trap and abort. Interrupts and exceptions both abruptly bring the current flow of execution of instructions to a standstill. Interrupts are prioritized meaning interrupts with high priority need immediate attention and are handled first. When an interrupt or an exception is detected, the processor executed an interrupt handler or exception handler while suspending the ongoing process. The processor resumes control of the interrupted process as soon as the execution of the handler is done.

Interrupt vs. Exception: Comparison Chart

Summary

Both interrupts and exceptions are unexpected events occur somewhere in the system, the processor, or within a program that requires immediate attention of the CPU. Both abruptly bring the current flow of execution of instructions to a standstill. When an interrupt or an exception is detected, the processor executed an interrupt handler or exception handler while suspending the ongoing process. The processor resumes control of the interrupted process as soon as the execution of the handler is done. If there are multiple interrupts, the interrupt with the highest priority should be handles first. One key difference between the two conditions is that interrupts are triggered by external events while exceptions are triggered from within the processor.

Latest posts by Sagar Khillar (see all)

Search DifferenceBetween.net :

Custom Search


Help us improve. Rate this post! 1 Star2 Stars3 Stars4 Stars5 Stars
Loading...

Email This Post Email This Post : If you like this article or our site. Please spread the word. Share it with your friends/family.


Leave a Response

Please note: comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

References :


[0]Li, Yamin. Computer Principles and Design in Verilog HDL. New Jersey, United States: John Wiley & Sons, 2015. Print

[1]Ledley, Robert and Shuangbao Paul Wang. Computer Architecture and Security: Fundamentals of Designing Secure Computer Systems. New Jersey, United States: John Wiley & Sons, 2012. Print

[2]Li, Qing and Caroline Yao. Real-Time Concepts for Embedded Systems. Florida, United States: CRC Press, 2003. Print

[3]Mejia-Alvarez, Pedro, et al. Interrupt Handling Schemes in Operating Systems. Berlin, Germany: Springer, 2018. Print

[4]Image credit: https://commons.wikimedia.org/wiki/File:Interrupt_Process.PNG

[5]Image credit: https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Java_exception_classes.svg/500px-Java_exception_classes.svg.png

Articles on DifferenceBetween.net are general information, and are not intended to substitute for professional advice. The information is "AS IS", "WITH ALL FAULTS". User assumes all risk of use, damage, or injury. You agree that we have no liability for any damages.


See more about : ,
Protected by Copyscape Plagiarism Finder