当前位置: 首页 > news >正文

解决:During handling of the above exception, another exception occurred


解决:During handling of the above exception, another exception occurred



文章目录

  • 解决:During handling of the above exception, another exception occurred
    • 背景
    • 报错问题
    • 报错翻译
    • 报错位置代码
    • 报错原因
    • 解决方法
    • 参考内容:
      • 今天的分享就到此结束了



背景

在使用之前的代码时,报错:
Traceback (most recent call last):
File “xxx”, line xx, in
re = request.get(url)
During handling of the above exception, another exception occurred



报错问题

Traceback (most recent call last): File "xxx", line xx, in  re =  request.get(url) During handling of the above exception, another exception occurred


报错翻译

主要报错信息内容翻译如下所示:

Traceback (most recent call last): File "xxx", line xx, in  re =  request.get(url) During handling of the above exception, another exception occurred

翻译:

追溯(最近一次调用):
文件“xxx”,第xx行,在
re=request.get(url)
在处理上述异常的过程中,发生了另一个异常



报错位置代码


...re =  request.get(url) 
...


报错原因

经过查阅资料,发现是这个错误通常是由于在处理异常的except分支或离开tryfinally分支有raise,就会出现这样的提示。

本例中的程序连续发起数千个请求,大量请求失败就会报这个错误:During handling of the above exception, another exception occurred

小伙伴们按下面的解决方法即可解决!!!



解决方法

要解决这个错误,需要可以使用try捕获异常但不用raise,即可解决。

正确的代码是:


...try:re =  request.get(url)exceptprint("time out")...

当报错发生在except时,需要在except的代码块里增加异常的try...except...,再次进行异常处理。可以参考如下代码:


x = 1
y = 0try:result = x / y
except ZeroDivisionError:print("处理第一个except")try:result = x / yexcept Exception as e:print("处理第二个except")print(repr(e))

当报错发生在finally时,需要在finally的代码块里增加异常的try...except...,再次进行异常处理。可以参考如下代码:


x = 1
y = 0try:result = x / y
except ZeroDivisionError:print("处理第一个except")finally:try:result = x / yexcept Exception as e:print("处理第二个except")print(repr(e))


参考内容:

https://blog.csdn.net/weixin_39514626/article/details/111839821



今天的分享就到此结束了

欢迎点赞评论关注三连

在这里插入图片描述

http://www.lryc.cn/news/255897.html

相关文章:

  • 计算机基础知识65
  • Python开发运维:Python垃圾回收机制
  • ros2/ros安装ros-dep||rosdep init错误
  • 《深入理解计算机系统》学习笔记 - 第四课 - 机器级别的程序
  • 云原生(Cloud Native)——概念,技术,背景,优缺点,实践例子
  • ElasticSearch之线程池
  • StoneDB-8.0-V2.2.0 企业版正式发布!性能优化,稳定性提升,持续公测中!
  • 【数据结构 — 排序 — 插入排序】
  • 物联网后端个人第十四周总结
  • 在uniapp中,可以使用那些预定义的样式类
  • mybatis的数据库连接池
  • Vue 的 el-select 下拉选项中,只有当文字超出时才显示提示框,未超出的则不显示
  • 【Python】pptx文件转pdf
  • response应用及重定向和request转发
  • CentOS常用基础命令大全(linux命令)2
  • 分析阿里巴巴的微服务依赖图和性能
  • Linux——基本指令(一)
  • 虚幻学习笔记10—C++函数与蓝图的通信
  • 无重复字符的最长子串(LeetCode 3)
  • 交付《啤酒游戏经营决策沙盘》的项目
  • 油猴(Tampermonkey)浏览器插件简单自定义脚本开发
  • BGP综合
  • 库函数qsort的使用及利用冒泡排序模拟实现qsort
  • mybatis和mybatisplus中对 同namespace 中id重复处理逻辑源码解析
  • linux下部署frp客户端服务端-内网穿透
  • Markdown to write
  • ResNeXt(2017)
  • DreamPlace 的下载安装与使用
  • FPGA模块——SPI协议(读写FLASH)
  • SQL自学通之表达式条件语句与运算