replace catch+throw with finally !ok, to get rid of UnhandledException shown as error

method declared as throwing only IOException, but unchecked exceptions can always happen
pull/606/head
Kai Morich 2024-06-23 19:17:43 +02:00
rodzic 275590027b
commit 843792001f
1 zmienionych plików z 8 dodań i 5 usunięć

Wyświetl plik

@ -117,6 +117,7 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
throw new IllegalArgumentException("Connection is null");
}
mConnection = connection;
boolean ok = false;
try {
openInt();
if (mReadEndpoint == null || mWriteEndpoint == null) {
@ -124,11 +125,13 @@ public abstract class CommonUsbSerialPort implements UsbSerialPort {
}
mUsbRequest = new UsbRequest();
mUsbRequest.initialize(mConnection, mReadEndpoint);
} catch(Exception e) {
try {
close();
} catch(Exception ignored) {}
throw e;
ok = true;
} finally {
if (!ok) {
try {
close();
} catch (Exception ignored) {}
}
}
}