Exceptions are run-time anomalies that a program may detect. Exception handling is the process of responding to the occurrence, during computation, of exceptions or exceptional conditions requiring special processing. An exception is a problem that arises during the execution of the program. A C++ exceptions a type of response for an exceptional situation that arises while a program is running, in such types of situation as an attempt to divide by zero. The errors occurred in the program may be logical errors or syntactic errors. The logical errors remain in the program due to an unsatisfactory understanding of the program. The goal of exception handling is to create a routine that detects and sends an exceptional condition in order to execute suitable actions.
An exception is an unusual event and may require special processing. The special processing required after detection of an exception is called exception handling. The exception handling code unit is called an exception handler.
Traditional approaches in case of an exception:
1. For termination of program: exit(), abort()
2. Return special values to indicate errors in a function
3. Set global error bits and return normally (leaving the system in an illegal state)
Error detection and handling code is tedious to write; it clutters the program and is error-prone
The C++ language provides built-in features to raise and handle exceptions:
1. Separate error-handling code from an ordinary code
2. Exception propagation allows a high level of reuse of exception handling code
3. Release local resources automatically
Standard Exceptions in C++ Language Library:
1. std:: exception:- This is the Parent class of all the standard C++ exceptions.
2. logic_error:- Exception happens in the internal logical of a program code.
3. domain_error:- Exception due to use of the invalid domain.
4. invalid argument:- Exception due to the invalid argument.
5. out_of_range:- Exception due to out of range.
6. length_error:- Exception due to length error.
7. runtime_error:- Exception happens during runtime.
8. range_error:- Exception due to range errors in internal computations.
9. overflow_error:- Exception due to arithmetic overflow errors.
10. underflow_error:- Exception due to arithmetic underflow errors
11. bad_alloc:- Exception happens when memory allocation with new() fails.
12. bad_cast:- Exception happens when dynamic cast fails.
13. bad_exception:- Exception is specially designed to be listed in the dynamic-exception-specifier.
14. bad_typeid:- Exception is thrown by typeid.
An exception is an unusual event and may require special processing. The special processing required after detection of an exception is called exception handling. The exception handling code unit is called an exception handler.
Traditional approaches in case of an exception:
1. For termination of program: exit(), abort()
2. Return special values to indicate errors in a function
3. Set global error bits and return normally (leaving the system in an illegal state)
Error detection and handling code is tedious to write; it clutters the program and is error-prone
The C++ language provides built-in features to raise and handle exceptions:
1. Separate error-handling code from an ordinary code
2. Exception propagation allows a high level of reuse of exception handling code
3. Release local resources automatically
Standard Exceptions in C++ Language Library:
1. std:: exception:- This is the Parent class of all the standard C++ exceptions.
2. logic_error:- Exception happens in the internal logical of a program code.
3. domain_error:- Exception due to use of the invalid domain.
4. invalid argument:- Exception due to the invalid argument.
5. out_of_range:- Exception due to out of range.
6. length_error:- Exception due to length error.
7. runtime_error:- Exception happens during runtime.
8. range_error:- Exception due to range errors in internal computations.
9. overflow_error:- Exception due to arithmetic overflow errors.
10. underflow_error:- Exception due to arithmetic underflow errors
11. bad_alloc:- Exception happens when memory allocation with new() fails.
12. bad_cast:- Exception happens when dynamic cast fails.
13. bad_exception:- Exception is specially designed to be listed in the dynamic-exception-specifier.
14. bad_typeid:- Exception is thrown by typeid.
Post A Comment:
0 comments: