Search code examples
exceptionoperating-systemos-trap

Difference between TRAP and exceptions


Taking an Operating System course. So I've understood both TRAPs and exceptions can be considered software interrupts... so they are both internal and synchronous. However I can't seem to figure out the difference between the two definitions. So if anybody wouldn't mind explaining and giving some examples it'd be highly appreciated.

Thanks.


Solution

  • Traps are initiated by the programmer using the instruction Int in x86. As soon as this instruction is encountered the program control gets transferred to the special handler routine. Whenever an abnormal condition occurs, exceptions are raised. For example, divide-by-zero condition. The program control is transferred to the exception handlers which are user-defined.