Which object is valid after the try block runs?

Given this code fragment:
<code>
ResultSet rs = null;
try (Connection conn = DriverManager. getConnection (url) ) {
Statement stmt = conn.createStatement();
rs stmt.executeQuery(query);
//-.. other methods }
} catch (SQLException se) {
System.out.println (“Error”);
}
</code>
Which object is valid after the try block runs?

Given this code fragment:

ResultSet rs = null;
try (Connection conn = DriverManager. getConnection (url) ) {
Statement stmt = conn.createStatement();
rs stmt.executeQuery(query);
//-.. other methods }
} catch (SQLException se) {
System.out.println ("Error");
}

Which object is valid after the try block runs?

A.
The Connection object only

B.
The Statement object only

C.
The Result set object only

D.
The Statement and Result Set object only

E.
The connection, statement, and ResultSet objects

F.
Neither the Connection, Statement, nor ResultSet objects

Explanation:
Generally, JavaScript has just 2 levels of scope: global and function. But, try/catch is
an exception (no punn intended). When an exception is thrown and the exception object gets a
variable assigned to it, that object variable is only available within the “catch” section and is
destroyed as soon as the catch completes.



Leave a Reply 1

Your email address will not be published. Required fields are marked *