From 3f1e5bb44af25fb4834036fddcbe9bab3401d2c6 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 18 Sep 2015 12:27:10 +0200 Subject: [PATCH] Catch exceptions when trying to eject the SD card on Windows CURA-106 #start-review --- .../WindowsRemovableDrivePlugin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py b/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py index 3723d48231..5e14bf933e 100644 --- a/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py +++ b/plugins/RemovableDriveOutputDevice/WindowsRemovableDrivePlugin.py @@ -88,10 +88,13 @@ class WindowsRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin): result = None # Then, try and tell it to eject - if not windll.kernel32.DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, None, None, None, None, None, None): + try: + if not windll.kernel32.DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, None, None, None, None, None, None): + result = False + else: + result = True + except Exception as e: result = False - else: - result = True # Finally, close the handle windll.kernel32.CloseHandle(handle)