I am currently writing a wrapper class for OpenCVs implementation of capturing images with a webcam. I want to catch the error exception when the space on disk is full. The code for it would look like the following:
cap = cv2.VideoCapture(cam_idx)
ret, frame = cap.retrieve()
try:
cv2.imwrite('test.png',frame)
except IOError:
print("ERROR ON WRITING")
While this will catch the exception, I was wondering if this will also catch other Exceptions and how to only catch the exception for disk full, and what would be the best practice for making a test for this code snippet (besides filling up my disk with so much stuff that the hard drive is really full)
Use OSError and check a result for errno.ENOSPC:
except OSError as e:
if e.errno == errno.ENOSPC:
To check free disk space you can use:
psutil.disk_usage(path).free
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With