题目
IS 4485-001 Fall 2025 Final Exam Practice 2
单项选择题
Which of these is the correct way to create a class-level exception?
选项
A.MyError = Exception()
B.raise MyError
C.class MyError: pass
D.def MyError(Exception): pass
E.class MyError(Exception): pass
查看解析
标准答案
Please login to view
思路分析
To determine the correct approach for creating a class-level exception, we should examine what each option actually does or defines.
Option 1: 'MyError = Exception()' assigns an instance of Exception to the name MyError. This does not define a new exception class; it simply creates an object, so it cannot be used as a type for raising or subclassing. This makes it incorrect for ......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
Consider the following code segment: try : inputFile = open("lyrics.txt", "r") line = inputFile.readline() print(line) _____________________ print("Error") What should be placed in the blank so that the program will print Error instead of crashing if an exception occurs while opening or reading from the file?
Python's error handling process includes the finally clause. In the following code snippet, when is the finally clause executed? inputFile = open("lyrics.txt", "r") try : line = inputFile.readline() words = line.split() print(words) finally : inputFile.close()
It is good programming practice to plan for possible exceptions and provide code to handle the exception. Which exception must be handled to prevent a divide by zero logic error?
What does the else block in exception handling do?
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!