Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/org/hid4java/HidServicesListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,18 @@ public interface HidServicesListener extends EventListener {
*/
void hidDataReceived(HidServicesEvent event);

/**
* An uncaught exception was thrown
* <p>
* <b>Note:</b> Any exceptions that occur in this callback will
* be silently ignored.
*
* @param event The event
* @param cause The uncaught exception
*/
@SuppressWarnings({"unused", "CallToPrintStackTrace"})
default void hidListenerException(HidServicesEvent event, Throwable cause) {
/* TODO: more robust logging */
cause.printStackTrace();
}
}
25 changes: 20 additions & 5 deletions src/main/java/org/hid4java/event/HidServicesListenerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ public void run() {
HidServicesEvent event = new HidServicesEvent(hidDevice);

for (final HidServicesListener listener : toArray()) {
listener.hidDeviceAttached(event);
try {
listener.hidDeviceAttached(event);
} catch(Throwable cause) {
listener.hidListenerException(event, cause);
}
}

}
});

}

/**
Expand All @@ -139,7 +142,11 @@ public void run() {
HidServicesEvent event = new HidServicesEvent(hidDevice);

for (final HidServicesListener listener : toArray()) {
listener.hidDeviceDetached(event);
try {
listener.hidDeviceDetached(event);
} catch(Throwable cause) {
listener.hidListenerException(event, cause);
}
}

}
Expand All @@ -163,7 +170,11 @@ public void run() {
HidServicesEvent event = new HidServicesEvent(hidDevice);

for (final HidServicesListener listener : toArray()) {
listener.hidFailure(event);
try {
listener.hidFailure(event);
} catch(Throwable cause) {
listener.hidListenerException(event, cause);
}
}

}
Expand All @@ -188,7 +199,11 @@ public void run() {
HidServicesEvent event = new HidServicesEvent(hidDevice, dataReceived);

for (final HidServicesListener listener : toArray()) {
listener.hidDataReceived(event);
try {
listener.hidDataReceived(event);
} catch(Throwable cause) {
listener.hidListenerException(event, cause);
}
}

}
Expand Down