PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 84


What is true about the following snippet? (Choose two.)

Show Answer
Correct Answer: BD

BD

Discussion

10 comments
Sign in to comment
rotimislawOptions: BC
Nov 15, 2022

B. the string I feel fine will be seen - it happens before any exception is raised C. unhandled exception is raised and writes down "Exception: what a pity", not only "what a pity" as the answer D states

luckymukiOptions: BC
Oct 25, 2021

The answer is B,C

techdawgs
Dec 4, 2021

It actually is BD. The string "what a pity" is the error message displayed so technically it will be seen along with "I feel fine".

TheNetworkStudentOptions: BD
Mar 6, 2022

Although answer B, C and D are correct. I think B and D are the 'best' answers. Because C an unhandled exception is raised, D is true. B is true because the line is printed before C and D happen.

macxszOptions: BD
May 3, 2022

B. the string I feel fine will be seen D. the string what a pity will be seen

DTL001Options: BC
Dec 19, 2021

Answer in BD, I've tested: class E(Exception): def __init__(self, message): self.message = message def __str__(self): return "It's nice to see you" try: print("I fell fine") raise Exception("What a party") except E as e: print(e) else: print("the show must go on") #Output: #I fell fine #Traceback (most recent call last): # File "C:\devops\python\t.py", line 9, in <module> # raise Exception("What a party") #Exception: What a party

sadako11Options: BC
Feb 15, 2022

the message 'I fell fine' will be seen and the code will raise an unhandled exception and the message 'what a pity ' will be seen. The answers could be B,C or D

mplopezOptions: BD
Aug 27, 2023

The B option is correct because the string I feel fine is printed on screen, and the D option is printed too.

zantrzOptions: BC
Feb 1, 2024

The raise Exception("What a pity") line raises a generic Exception, not an instance of the custom exception E. Since the except E as e block is specifically looking for instances of E, it won't catch the raised exception, and the control will go directly to the else block. However! The program terminates abruptly after encountering the unhandled Exception, and the else block doesn't get a chance to execute. When an unhandled exception occurs, the normal program flow is disrupted, and subsequent code (including the else block) is skipped. To make the else block execute, you would need to handle the exception, either by catching it with the correct except block or allowing the program to handle it at a higher level.

Damon54Options: AD
Feb 6, 2024

The code could also be like this perhaps class E(Exception): def __init__(self, message): self.message = message def __str__(self): return "It's nice to see you" try: print("I feel fine") raise Exception("what a pity") except Exception as e: print(e) else: print("the show must go on")

CoinUmbrellaOptions: BD
May 14, 2024

B.D. watch video. Answer broken down at 47 minutes. https://www.youtube.com/watch?v=Tme3Op1_IPk