C++ Exception handling
we know that is very rare that a program works correctly first time . It might have bugs. The two most common types of bugs are logic error and syntactic errors. The logic errors occurs due to poor understanding of the problem and solution procedure. The syntactic problems or errors arise due to poor understanding of the language itself.we can detect these errors by using exhaustive debugging and testing procedures
We often come across some peculiar problems other than login or syntax errors. They are known as exception.
Exception are run time anomalies or unusual conditions that a program may encounter while execution. Anomalies might include conditions
such as division by zero , access the array outside of its bounds or size, or running out of memory or disk space, when a program encounters an exceptional condition. It is very important that it is identified and dealt with effectively ANSI C++ language provides built in language features to detect and handled exception which are basically run time errors.
the EXCEPTION handling is not a part of c++, it is a new feature added to ANSI c++ today , almost all compilers support this feature.in C++ language the exception handling provides a type safe integrated approach for coping with the unusual predictable problems that arise while executing a program.
BASIC OF EXCEPTION HANDLING
Exception are two kinds,namely, synchronous exceptions and asynchronous exceptions.Error such as “out of range index” and “over flow” belongs to the synchronous type exceptions. The error that are caused by the events beyond the control of program(such as keyboard interrupts) are called asynchronous exceptions. The proposed exception handling mechanism in c++ language is designed to handled only synchronous exceptions.
The purpose of the exception handling 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 step by step 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(Handled 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