Welcome to this quiz on one of the most critical aspects of C++ - Exception Handling. Exception handling allows developers to manage unforeseen errors and provide ways to handle them gracefully without crashing the entire application. Let's test your knowledge of this essential topic!
1. Which keyword is used to handle an exception?
a) catch
b) throw
c) try
d) handle
2. Which keyword is used to signal the occurrence of an exception?
a) signal
b) raise
c) alert
d) throw
3. What is the purpose of the try block?
a) To catch the exception
b) To throw the exception
c) To encapsulate potential exception-throwing code
d) None of the above
4. Which of the following can be thrown as an exception in C++?
a) int
b) char
c) an object
d) All of the above
5. If you have multiple catch blocks for a try block, how are they executed?
a) All catch blocks are executed sequentially
b) Only the first catch block is executed
c) Only the catch block matching the thrown exception type is executed
d) Last catch block is executed
6. Which standard library class can be used for exception handling in C++?
a) exception
b) stdexcept
c) exceptions
d) error
7. What will happen if an exception is not caught?
a) The program continues normally
b) The program crashes
c) The exception is ignored
d) The exception is caught by the OS
8. Which keyword is used to specify a block of code that must be executed after the try-catch block?
a) finally
b) lastly
c) conclude
d) None of the above
9. What is the base class for all standard exception classes?
a) error
b) std::exception
c) std::base_exception
d) throw
10. Which of the following is not a standard exception derived from std::exception?
a) std::bad_alloc
b) std::out_of_range
c) std::throws
d) std::length_error
Exception handling is a critical aspect of C++, offering developers a way to predictably manage unforeseen errors. Remember, understanding how to utilize exception handling can make your software robust and user-friendly. How did you fare in this quiz? Keep studying and practicing to master all aspects of C++!
Comments
Post a Comment