Which keyword is used in C++ to handle exceptions?
A
error B
exception C
catch D
handle
Analysis & Theory
The `catch` keyword is used to catch exceptions thrown using `throw` in C++.
What is the purpose of the `try` block in C++?
A
To test a block of code for errors B
To catch exceptions C
To throw exceptions D
To terminate the program
Analysis & Theory
The `try` block contains code that might throw an exception.
What will happen if no catch block is found for a thrown exception?
A
The program continues B
The program stops with an error C
It returns 0 D
Nothing happens
Analysis & Theory
If no matching `catch` block is found, the program terminates with a runtime error.
Which of the following is a valid syntax for throwing an exception?
A
throw; B
throw error(); C
throw 'Error'; D
throw catch();
Analysis & Theory
`throw 'Error';` throws a string literal as an exception.
Which of the following can be caught using catch(...) in C++?
A
Only int B
Only string C
Any exception D
Syntax errors
Analysis & Theory
`catch(...)` is used to catch all types of exceptions.
What type of error is handled by exception handling in C++?
A
Syntax errors B
Linker errors C
Logical errors D
Runtime errors
Analysis & Theory
C++ exceptions are used to handle runtime errors only.
Which keyword is used to re-throw an exception in C++?
A
retry B
throw C
catch D
error
Analysis & Theory
The `throw;` statement (with no operand) re-throws the currently handled exception.
Which of the following is true about multiple catch blocks?
A
Only one catch block is allowed B
Multiple catch blocks are not allowed C
Multiple catch blocks can follow a try block D
All catch blocks must be identical
Analysis & Theory
Multiple `catch` blocks can follow a `try` block to handle different exception types.
What is the standard exception base class in C++?
A
std::error B
std::exception C
exception D
std::runtime_error
Analysis & Theory
`std::exception` is the base class for all standard exceptions in C++.
Which of the following is NOT a standard exception in C++?
A
std::logic_error B
std::runtime_error C
std::file_error D
std::bad_alloc
Analysis & Theory
`std::file_error` is not a standard C++ exception.