P
P
pqgg7nwkd42017-08-28 19:38:54
Java
pqgg7nwkd4, 2017-08-28 19:38:54

How to throw a JNA exception up?

Let me explain the question in code:

public static void main(String... args) {
        User32 user32 = Native.loadLibrary("user32", User32.class, W32APIOptions.DEFAULT_OPTIONS);
        try {
            user32.EnumChildWindows(
                    null /*hWnd, с таким аргументом выхов callback произойдет*/,
                    (hWnd, data) -> {
                        throw new RuntimeException("Test");
                    },
                    null /*data*/);
            System.out.println("Test exception is not catched :("); // Попадаем сюда
        } catch (Throwable t) {
            System.out.println("Test exception catched :)"); // А хотелось бы сюда
        }
    }

I tried to rethrow the exception in Native.setCallbackExceptionHandler, but the result is the same.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2017-08-28
@jkotkot

I suspect not. Is that through the closure to set some flag.

T
Tiberal, 2017-08-29
@Tiberal

You can try to play around with this
https://docs.oracle.com/javase/7/docs/api/java/lan...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question