一.说明 1.python进程池进行多进程运行时,如果有错误,该进程会直接跳过,并且不会打印错误信息. 2.如果需要了解到进程内的错误信息,此时就需要通过捕获异常来输出错误信息了. 二.具体方法如下: 法一: 注:此方法不会打印错误代码具体位置 a = [1, 2, 3] try: b = a[5] except Exception as ee: print(ee) s = ee # 如果想在except语句外使用ee,需要用变量储存 # 输出ee: # list index out of ra
异常捕获 try: execpt Exception as e: print(str(e)) 打印异常信息的方式 1.str(e) 返回字符串类型,只给出异常信息,不包括异常信息的类型,如1/0的异常信息 'integer division or modulo by zero' 2.e.message 获得的信息同str(e) 3.repr(e) 给出较全的异常信息,包括异常信息的类型,如1/0的异常信息 "ZeroDivisionError('integer division or modul
shell脚本中sqlite3命令查询数据库失败返回空,并将错误信息打印到标准错误输出 如: #/bin/sh local ret='sqlite3 test.db "select test from test;"' 或: local ret=$(sqlite3 test.db "select test from test;") 如果test.db被锁定,ret将为空,标准错误输出有信息“Error:database is locked”.