Skip to content

Commit

Permalink
replace catch+throw with finally !ok, to get rid of UnhandledExceptio…
Browse files Browse the repository at this point in the history
…n shown as error

method declared as throwing only IOException, but unchecked exceptions can always happen
  • Loading branch information
kai-morich committed Jul 5, 2024
1 parent 2755900 commit 8437920
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,21 @@ public void open(UsbDeviceConnection connection) throws IOException {
throw new IllegalArgumentException("Connection is null");
}
mConnection = connection;
boolean ok = false;
try {
openInt();
if (mReadEndpoint == null || mWriteEndpoint == null) {
throw new IOException("Could not get read & write endpoints");
}
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) {}
}
}
}

Expand Down

0 comments on commit 8437920

Please sign in to comment.