I defined a function in Kotlin:
fun convertExceptionToEmpty(requestFunc: () -> List<Widget>): Stream<Widget> { try { return requestFunc().stream() } catch (th: Throwable) { // Log the exception... return Stream.empty() } }
I defined a Java method with this signature:
List<Widget> getStaticWidgets() throws IOException;
I try to compose them like this:
Stream<Widget> widgets = convertExceptionToEmpty(() -> getStaticWidgets())
When compiling, I get this error:
Error: (ln, col) java: unregistered exception java.io.IOException; must be caught or declared abandoned
How to determine the parameters of my function to accept the function that throws?
java lambda java-8 throws kotlin
Michael richardson
source share