C++:Exception Handling|syntax


The basic concepts of exception handling are throwing an exception and catching it. This is illustrated in the given figure

The purpose of an exception handling mechanism is to provide a means to detect and report “exceptional circumstances” so that appropriate actions can be taken.

The mechanism suggests incorporation of 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 exceptions and to take appropriate actions.

When writing programs we must always be on the lookout for places in the program where an exception could be generated.