开发者学堂课程【Python 基础快速入门实战教程:Python 异常处理实战】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/452/detail/5592
Python 异常处理实战
内容简介:
一、异常处理概述
二、异常处理实战
一、异常处理概述
Python 程序在执行的时候,经常会遇到异常,如果中间异常不处理,经常会导致程序崩溃。比如后面我们写爬虫的时候,如果不进行异常处理,很可能虫爬了一半,直接崩溃了。
二、异常处理实战
代码如下:
#异常处理
‘’’
异常处理格式
try:
程序
except Exception as 异常名称:
异常处理部分
‘’’
try:
for i in range(0,10):
print(i)
if (i==4):
print(jkj)
print("hello")
except Exception as err:
print(err)
#让异常后的程序继续
for i in range(010):
try:
Print (i)
if(i==4):
print(jkj)
except Exception as err:
print(err)
print("hello")