这是我的Python代码的一小部分:
except Exception1:
logger.error("Exception 1. Exit.")
sys.exit(-1)
except Exception 2, e:
logger.error("Exception 2: {e}".format(e=e.message))
有时我会收到错误消息:
INFO - 2019-01-28 16:44:49,399 - data_loader - ERROR - Exception 2: [Errno 28] No space left on device
问题是程序返回0代码,我看不到错误。
我找到了两种解决方案。
1:
except Exception1:
logger.error("Exception 1. Exit.")
sys.exit(-1)
except Exception 2, e:
logger.error("Exception 2: {e}".format(e=e.message))
raise
2:
except Exception1:
logger.error("Exception 1. Exit.")
sys.exit(-1)
except Exception 2, e:
logger.error("Exception 2: {e}".format(e=e.message))
except [ExceptionCode]:
raise("No space left on device")
我的问题是-如何在Pyhton中捕获“设备上没有剩余空间”?我可以使用任何错误代码吗?
答案 0 :(得分:1)
NotificationCenter.default.addObserver(self, selector: #selector(ImageScrollView.changeOrientationNotification), name: Notification.Name.UIDevice.orientationDidChangeNotification, object: nil)
答案 1 :(得分:0)
如果它是有效的异常,则您将获得如下所示的异常名称。一旦有了名称,就可以优雅地处理该异常
try:
#do something
except Exception as exception:
print(exception.__class__.__name__)