码迷,mamicode.com
首页 > 编程语言 > 详细

Python --- 异常处理

时间:2020-07-11 17:18:36      阅读:54      评论:0      收藏:0      [点我收藏+]

标签:遇到   异常   print   err   range   部分   ==   导致   python   

异常处理概述

Python程序在执行的时候,经常会遇到异常,如果中间异常不处理,经常会导致程序崩溃。比如后面我们写爬虫的时候,如果不进行异常处理,很可能虫爬了一半,直接崩溃了。

异常处理

异常处理格式

try:
	程序
except Exception as 异常名称:
	异常处理部分
try:
	for i in range(0,10):
		print(i)
		if(i == 4):
			print(j)
	print("hello")
except Exception as err:
	print(err)

Python --- 异常处理

标签:遇到   异常   print   err   range   部分   ==   导致   python   

原文地址:https://www.cnblogs.com/bingers/p/13284081.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!