Skip to content

Commit 1b222f2

Browse files
committed
error handling
1 parent c280d7e commit 1b222f2

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/main/java/dev/codeman/smtc4j/SMTC4J.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ public static synchronized void startUpdateScheduler(long intervalMillis) {
8484
checkIsLoaded();
8585

8686
ScheduledExecutorService exec = getScheduler();
87-
exec.scheduleAtFixedRate(SMTC4J::updateCache, 0, intervalMillis, TimeUnit.MILLISECONDS);
87+
exec.scheduleAtFixedRate(() -> {
88+
try {
89+
updateCache();
90+
} catch (Exception e) {
91+
System.err.println("Error updating SMTC4J cache: " + e.getMessage());
92+
e.printStackTrace(System.err);
93+
}
94+
}, 0, intervalMillis, TimeUnit.MILLISECONDS);
8895
}
8996

9097
public static MediaInfo parsedMediaInfo() {
@@ -130,7 +137,14 @@ public static void pressKey(MediaKey key) {
130137
public static void scheduleKeyPress(MediaKey key) {
131138
checkIsLoaded();
132139

133-
getScheduler().execute(() -> pressKey(key));
140+
getScheduler().execute(() -> {
141+
try {
142+
pressKey(key);
143+
} catch (Exception e) {
144+
System.err.println("Error pressing media key: " + e.getMessage());
145+
e.printStackTrace(System.err);
146+
}
147+
});
134148
}
135149

136150
private static void checkIsLoaded() {

0 commit comments

Comments
 (0)