Skip to main content

Exception Handling

1).What is the purpose of exception handling in C++?

1) To handle errors
2) To make code more readable
3) To optimize performance
4) None of the above

2).Which of the following keywords is used to throw an exception?

1) throw
2) catch
3) try
4) exception

3).What is the keyword used to handle an exception?

1) catch
2) try
3) throw
4) exception

4).Which of the following is the correct syntax for handling exceptions?

1) try { // code } catch(exception e) { // code }
2) catch(exception e) { // code } try { // code }
3) try catch { // code }
4) None of the above

5).Can a C++ function throw multiple exceptions?

1) Yes
2) No
3) Only for different types
4) Only in specific cases

6).What happens when an exception is not caught?

1) Program terminates
2) Exception is ignored
3) A default exception handler is invoked
4) None of the above

7).What is a standard exception in C++?

1) An exception that is defined in the C++ standard library
2) A user-defined exception
3) An exception that is raised by the compiler
4) None of the above

8).What does the 'throw' keyword do?

1) Throws an exception
2) Catches an exception
3) Terminates the program
4) None of the above

9).Which class is the base class for all exceptions in C++?

1) std::exception
2) std::runtime_error
3) std::error
4) None of the above

10).What is a 'catch' block used for?

1) To handle exceptions
2) To throw exceptions
3) To define exception types
4) None of the above