C++ Error Handling: Interview questions
Describe the way to handle run time error in C++.
Latest answer: A runtime error is handled in C++ in the
following manner:
- Write the code where the error is predicted after the keyword try.
- Write the solution if a particular exception occurs in the catch block by
specifying a parameter which is thrown from the try block.
Or
- Throw the error object by using throw(Exceptiontype object) after try
keyword.
-
Describe the way to handle run time error in C++.
-
Explain the exception specification.
Also read
Explain how we implement
exception handling in C++.
Exception handling in C++ is implemented by using the try{} and catch(){}
statements.
When a try block throws an exception, the program leaves the try block and
enters the catch statement of the catch block..................
Explain terminate() and unexpected()
function.
terminate() is a library function which by default aborts the program
It is called whenever the exception handling mechanism cannot find a handler
for a thrown exception...................
Describe Exception handling concept
with an example.
Exceptions: Exceptions are certain disastrous error conditions that
occur during the execution of a program. They could be errors that cause the
programs to fail or certain conditions that lead to errors. If these run time
errors are not handled by the program, OS handles them and program
terminates..................
Illustrate Rethrowing exceptions with an
example.
Rethrowing an expression from within an exception handler can be done by calling
throw, by itself, with no exception. This causes current exception to be passed
on to an outer try/catch sequence.......................
|