C++:Exception Handling| What is Exception

Managing Errors and Exception Handling

An error may produce an incorrect output or may terminate the execution of the program abruptly or even may cause the system to crash. It is therefore important to detect and manage properly all the possible error conditions in the program so that the program will not terminate or crash during execution.

Exception

An exception is a condition that is caused by a run time error in the program. When the Java interpreter/ C++ compiler encounters an error such as dividing an integer by zero, It creates an exception object and throws it.(i.e. informs us that an error has occurred)

If the exception object is not caught and handled properly, the interpreter/compiler will display an error message and will terminate the program.

If we want the program to continue with the execution of the remaining code then we should try to catch the exception object thrown by the error condition and hence display an appropriate message for taking corrective actions. This task is known as exception handling.