开发者社区> 问答> 正文

python如何指定异常?

python如何指定异常?

展开
收起
真的很搞笑 2021-12-03 22:35:08 369 0
1 条回答
写回答
取消 提交回答
  • 可以指定要在 except 块中处理哪个错误

    try: # some code except ValueError: # some code 现在它会捕获 ValueError 异常,但是不会捕获其他异常。如果我们希望该处理程序处理多种异常,我们可以在 except后面添加异常元组。

    try: # some code except (ValueError, KeyboardInterrupt): # some code 或者,如果我们希望根据异常执行不同的代码块,可以添加多个 except 块。

    try: # some code except ValueError: # some code except KeyboardInterrupt: # some code

    2021-12-03 22:35:47
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载