Top "Try-with-resources" questions

The try-with-resources statement is a try statement in Java that declares one or more resources.

How should I use try-with-resources with JDBC?

I have a method for getting users from a database with JDBC: public List<User> getUser(int userId) { …

java jdbc java-7 try-with-resources
Am I using the Java 7 try-with-resources correctly

I am expecting the buffered reader and file reader to close and the resources released if the exception is throw. …

java-7 try-with-resources
What is a suppressed exception?

A comment (by user soc) on an answer to a question about tail call optimisation mentioned that Java 7 has a …

java exception exception-handling try-with-resources
Close multiple resources with AutoCloseable (try-with-resources)

I know that the resource you pass with a try, will be closed automatically if the resource has AutoCloseable implemented. …

java sockets datainputstream try-with-resources autocloseable
Why write Try-With-Resources without Catch or Finally?

Why write Try without a Catch or Finally as in the following example? protected void processRequest(HttpServletRequest request, HttpServletResponse response) …

java try-with-resources
Transaction rollback on SQLException using new try-with-resources block

I have a problem with try-with-resources and I am asking just to be sure. Can I use it, if I …

java try-with-resources
IntelliJ IDE gives error when using Try-Catch with Resources

I am attempting to use JDK 7's "try-catch with resources" statement; IntelliJ highlights my resource line, saying Try-with-resources are not …

java intellij-idea try-catch try-catch-finally try-with-resources
Try / Try-with-resources and Connection, Statement and ResultSet closing

I have recently having some discussions with my professor about how to handle the basic jdbc connection scheme. Suppose we …

java correctness try-with-resources
Correct idiom for managing multiple chained resources in try-with-resources block?

The Java 7 try-with-resources syntax (also known as ARM block (Automatic Resource Management)) is nice, short and straightforward when using only …

java try-with-resources
Try-with-resources in Kotlin

When I tried to write an equivalent of a Java try-with-resources code in Kotlin, it didn't work for me. I …

kotlin extension-methods try-with-resources