python之终止代码运行之raise

发布时间 2023-03-26 14:37:06作者: 博无止境
raise函数可以终止代码的运行
print('hello')
raise '终止运行,并报异常'
print('word')


执行结果>>>:
hello
Traceback (most recent call last):
  File "D:/Users/72036454/Desktop/pythonProject2/test_002.py", line 3, in <module>
    raise '终止运行,并报异常'
TypeError: exceptions must derive from BaseException