In this Java program example:
package test;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
public class Test
{
private static void example(){
String url = "jdbc:oracle:thin:@//localhost:7856/xe";
String user = "user";
String password = "pass";
try(Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement()){
throw new OutOfMemoryError("Error");
}catch (SQLException e){
System.err.println("SQLException");
}
}
public static void main(String [] args){
try{
example();
}catch (OutOfMemoryError e){
System.err.println("OutOfMemoryError");
}
// Rest of code here...
}
}
When, in the body of the static method example(), the OutOfMemoryError error is thrown, Are Connection "con" and Statement "stmt" automatically closed before terminating the static method example() despite there is not any "catch" that catches these error so in the rest of code in main() is sure that these two objects are closed ?
Thanks.