This section contains 274 words (approx. 1 page at 300 words per page) |
Despite a programmer's best efforts, abnormal or illegal operations happen during the execution of program instructions. These deviations from the normal execution sequence are called exceptions. Processors detect exceptions when activities such as division by zero (impossible) or a request for memory allocation exceeds the available amount of storage occur. Exceptions can corrupt memory and create adverse side-effects if the program continues. The process of dealing with exceptions is called exception handling.
There is a wide variety of ways in which programming languages implement exception handling. Once an exception has been detected, it is raised. An exception is raised when an abnormal event occurs, information about that event is collected, and control is transferred to an exception handler. An exception handler performs a specified response to recover from the exception. The specified response can be to execute a corrective action or to ignore the exception.
Once the exception handler's action is executed, the program can resume normal processing, or it can terminate. Resumption of a process may require a statement to be reevaluated or it may return control to the point after which the exception occurred. Termination may involve the cessation of a portion of a program or the program in its entirety. If an exception handler does not exist, the run-time system can execute a default action, such as terminating the program.
Exception handling is used to improve the reliability of a program and make it robust. Robust programs handle exceptions gracefully, without undo interruption or bringing frustration upon the user. Exception handling can also be used to validate data and maintain the integrity of data or the environment.
This section contains 274 words (approx. 1 page at 300 words per page) |