raise表示会抛出异常那么就是说raise会向python的解释器一个响应告诉解释器他的后面是一个异常让我们的程序中断

一般是和自定义的异常连用。

class CustomError(Exception):
  def __init__(self):

def main():
try :
  s=input("请输入字符串:")
  if len(s)<3:
    raise CustomError(object1,object2)
except CustomError as result:
  print("使用了异常类产生的对象result")
else :
  print("没有异常产生")

main()

相关文章:

  • 2022-12-23
  • 2022-02-11
  • 2022-02-24
  • 2021-09-30
  • 2022-12-23
  • 2022-01-25
  • 2021-10-27
  • 2021-07-12
猜你喜欢
  • 2022-12-23
  • 2022-01-26
  • 2021-11-19
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案