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)
posted @ 2020-07-11 16:18  chstor  阅读(115)  评论(0编辑  收藏  举报