Skip to content
Advertisement

try-with-resource – finally keyword error on Java 8 [closed]

I have the following code which yields me a “Syntax error, insert “Finally” to complete TryStatement”.

JavaScript

Why do I get this error, and how can I write it better to eliminate the duplication of

JavaScript

but still use the “try-with-resource” implementation.

I based my code on http://tutorials.jenkov.com/java-exception-handling/try-with-resources.html

Advertisement

Answer

Your larger try block is not a try-with-resources, but rather a standard try. It therefore needs to have either a catch or finally block added to it.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement