Python 异常(Exception)
来源:互联网 发布:股票看行情软件 编辑:程序博客网 时间:2024/05/17 05:12
Python 异常(Exception)
形式1 try/except
try: 会出现异常的语句except 异常类型 as 对象名: 异常处理
例如:
try: 1/0except Exception as e: print(e)'''结果:division by zero'''
形式2 try/except/finally
try: 会出现异常的语句except 异常类型 as 对象名: 异常处理finally: 无论是否发生异常都会执行的部分
例如:
try: 1/0except Exception as e: print(e)finally: print('finally')'''结果:division by zerofinally'''
形式3 try/except/else/finally
try: 会出现异常的语句except 异常类型 as 对象名: 异常处理else: 不发生异常执行的代码finally: 无论是否发生异常都会执行的部分
例如:
try: 1/0except Exception as e: print(e)else: print('else')finally: print('finally')'''结果:division by zerofinally'''try: 1/2except Exception as e: print(e)else: print('else')finally: print('finally')'''结果:elsefinally'''
其他形式
try/except 是必须有的部分,else和finally是非必须的部分,其他形式的就是try/except和else和finally的组合形式
0 0
- Python 异常(Exception)
- Python 异常(Exception)
- Python中的异常(Exception)
- Python中获取异常(Exception)信息
- Python中获取异常(Exception)信息
- python的异常Exception
- python Exception 异常处理
- Python,异常 exception
- python异常 Exception
- Python Exception 异常处理
- Python 3语法小记(九) 异常 Exception
- Python 3语法小记(九) 异常 Exception
- Python 3语法小记(九) 异常 Exception
- 异常一(Exception)
- 异常二(Exception)
- 31、异常(Exception)
- 异常(Exception)
- 异常(Exception)
- 2-25 FlaskWeb开发 学习笔记及其他
- 锁机制
- Web基础之CSS(二)
- Python爬虫实战——模拟登录教务系统
- SessionFactory的创建方式
- Python 异常(Exception)
- 单例模式之懒汉的并发问题,只需要添加一个 synchronized 就可以解决了
- 欢迎使用CSDN-markdown编辑器
- HDU-6016 count the sheep
- leecode 解题总结:283. Move Zeroes
- Linux系统从零到高手的进阶心得
- 自学笔记一:C#语法基础 类
- PHP+JavaScript 实现图片无刷新上传
- mssql从入门到';drop table --