Python --- 异常处理

时间:2020-07-11 17:18:36   收藏:0   阅读:54

异常处理概述

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)
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!