Sobes.tech
Junior — Senior

Determining the order of calling close() methods in a try-with-resources block

livecode

Task condition

Given an announcement of three resources R1, R2, and R3. It is required to explain the following:

  • In what order will the close() calls be executed for the specified resources?
  • When exactly does the closing process start: before exiting the try block or after?
  • How will the mechanism behave if one of the close() methods throws an exception?
try (R1 r1 = ...; R2 r2 = ...; R3 r3 = ...) {
    ...
}