Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

C++ Institute Exam CPA-21-02 Topic 1 Question 11 Discussion

Actual exam question for C++ Institute's CPA-21-02 exam
Question #: 11
Topic #: 1
[All CPA-21-02 Questions]

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class myClass : public exception

{

virtual const char* what() const throw()

{

return "My exception.";

}

} obj;

int main () {

try

{

throw obj;

}

catch (exception& e)

{

cout << e.what() << endl;

}

return 0;

}

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Robt
1 days ago
Ah, the classic C++ exception handling question! This one's a breeze - the answer is clearly A. The code creates a custom exception class and throws an instance of it, which the catch block then properly handles and prints the expected message.
upvoted 0 times
...
Amber
8 days ago
I'm not sure, but I think D) Compilation error could also be a possibility if there is an issue with the code.
upvoted 0 times
...
Rima
10 days ago
I agree with Cordelia, because the code defines a custom exception class and throws an object of that class.
upvoted 0 times
...
Cordelia
14 days ago
I think the answer is A) It prints: My exception.
upvoted 0 times
...

Save Cancel