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:

Angella
3 days ago
Okay, let's see. We're throwing a custom exception, and the catch block is set up to handle exceptions of type exception&. I'm pretty sure that means it'll print the custom message, so I'm going with A as well.
upvoted 0 times
...
Alease
5 days ago
Hmm, let me think this through. The code is throwing a custom exception, so it should print the message we defined in the what() method. I'm going to go with A on this one.
upvoted 0 times
...
Robt
12 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
19 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
21 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
25 days ago
I think the answer is A) It prints: My exception.
upvoted 0 times
...

Save Cancel
az-700  pass4success  az-104  200-301  200-201  cissp  350-401  350-201  350-501  350-601  350-801  350-901  az-720  az-305  pl-300  

Warning: Cannot modify header information - headers already sent by (output started at /pass.php:70) in /pass.php on line 77