Friday, April 17, 2009

EXCEPTION HANDLING

Exception handling is the latest feature adder to ANSI C++, Exceptions refer to unusual conditions in a program. They could errors that cause the program to fail or certain conditions that lead to errors. When a program encounters an exceptional condition, it is important that it is dealt with.
Exceptions are of two kinds, namely, synchronous exceptions. Errors such as “out-of-range index” and “over-flow” belong to the synchronous type exceptions. The errors that are caused by events beyond the control of the program (such as keyboard interrupts) are called asynchronous exceptions. The proposed exception handling mechanism in C++ is designed to handle only synchronous exceptions.
The purpose of the exception handling mechanism is to provide means to detect and report an “exceptional circumstance” so that appropriate action can be taken. The mechanism suggests a separate error handling code that performs the following tasks:

1. Find the problem (Hit the exception).
2. Inform that an error has occurred (Throw the exception).
3. Receive the error information ( Catch the exception).
4. Take corrective actions (Handle the exception).


The error handling code basically consists of two segments, one to detect errors and to throw exceptions and the other to catch the exceptions and to take appropriate actions.

No comments:

Post a Comment