如何退出Python脚本而不在Python中抛出错误?
我使用一个调用Python脚本的SQL作业。。在某些情况下,我希望退出脚本而不会完全失败,但只需抛出一些消息。SQL作业有3个步骤,例如1。预处理2。过程3。后处理。。 因此,在某些情况下,希望退出预处理,但仍希望处理后处理。。下面是我的班级结构如何退出Python脚本而不在Python中抛出错误?,python,python-3.x,Python,Python 3.x,我使用一个调用Python脚本的SQL作业。。在某些情况下,我希望退出脚本而不会完全失败,但只需抛出一些消息。SQL作业有3个步骤,例如1。预处理2。过程3。后处理。。 因此,在某些情况下,希望退出预处理,但仍希望处理后处理。。下面是我的班级结构 class Test: def pre_process(): #some code sys.exit("exiting out of program") def process(): #some code
class Test:
def pre_process():
#some code
sys.exit("exiting out of program")
def process():
#some code
def post_process():
#some code
def run():
try:
pre_process()
process()
except Exception as e:
raise e
finally:
post_process()
所以这里的问题是代码正在退出,但有错误。但我想成功退出该计划。任何建议都是有帮助的
raise RuntimeError("Description of the error")
像这样的东西可以用
您还可以研究Python的不同循环中断方案。也许这会有帮助:只需使用不带参数的
sys.exit()
,就可以了。但我仍然希望向SQL代理作业传递某种消息,我如何才能实现这一点?