嗨,我目前正在做这样的程序。
class MyError(Exception):
def __init__(self, text = "Correct")
self.text = text
def __str__(self):
return (self.kod)
class Atom(self):
.
.
.
try:
function()
else:
raise MyError("Incorrect use of function")
def main():
try:
a = Atom()
except:
# Here i want to print the error that was raised
我想我理解的是错误是在 Atom() 中创建的对象中引发的。但我想将它发送到我的主程序并在那里打印错误 MyError 。是否可以这样做以及我应该如何编写它以便打印正确的异常文本,因为我将有几个不同的错误消息。
如果我来到 except 声明,我想打印“功能使用不正确”的消息。