Skip to content

Commit 6680bb3

Browse files
committed
Prevent exceptions from escaping FFM log callback
1 parent 37bb9f4 commit 6680bb3

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/main/java/io/github/doblon8/openpnp/capture/OpenPnpCapture.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ public static void setLogLevel(LogLevel level) {
5858
* which will be called for each log message generated by the library.
5959
*/
6060
public static void installCustomLogFunction(BiConsumer<LogLevel, String> logFunction) {
61-
MemorySegment functionPointer = CapCustomLogFunc.allocate((level, stringPointer) ->
62-
logFunction.accept(LogLevel.fromNative(level), stringPointer.getString(0)), arena);
61+
MemorySegment functionPointer = CapCustomLogFunc.allocate((level, stringPointer) -> {
62+
try {
63+
LogLevel logLevel = LogLevel.fromNative(level);
64+
String message = stringPointer.getString(0);
65+
logFunction.accept(logLevel, message);
66+
} catch (Throwable t) {
67+
t.printStackTrace(System.err);
68+
}
69+
}, arena);
6370
Cap_installCustomLogFunction(functionPointer);
6471
}
6572

0 commit comments

Comments
 (0)