Independence Day Deal! Unlock 25% OFF Today – Limited-Time Offer - 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:

Mariann
2 months ago
Wait, does this mean I can create my own exception classes and throw them around like candy? That's kind of awesome, if you ask me. Though I bet the compiler's gonna have a field day with all those custom exceptions flying around.
upvoted 0 times
Annamae
16 days ago
User3: The compiler might not like all those custom exceptions.
upvoted 0 times
...
Soledad
28 days ago
User2: It prints: My exception.
upvoted 0 times
...
Isadora
1 months ago
User1: Yes, you can create your own exception classes.
upvoted 0 times
...
...
Lenny
2 months ago
Haha, this one's a classic tricky C++ question. I bet a lot of people are going to overthink it and pick the wrong answer. But not me! I'm sticking with A - it's gotta be the custom exception message, no doubt about it.
upvoted 0 times
...
Angella
2 months 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
Sharmaine
1 hours ago
Yes, A seems to be the correct choice.
upvoted 0 times
...
Myra
4 days ago
So, we're all going with option A then?
upvoted 0 times
...
Fletcher
24 days ago
I agree, it should print the custom message.
upvoted 0 times
...
Merrilee
1 months ago
I think it prints: My exception.
upvoted 0 times
...
...
Alease
2 months 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
2 months 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
Melvin
1 months ago
I agree, the answer is definitely A.
upvoted 0 times
...
Colby
2 months ago
A) It prints: My exception.
upvoted 0 times
...
...
Amber
2 months 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
2 months ago
I agree with Cordelia, because the code defines a custom exception class and throws an object of that class.
upvoted 0 times
...
Cordelia
3 months 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