Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

try-with-resources

A try statement that declares resources in brackets and closes each one automatically, on every path.

try (R r = ...) { ... } calls close() once per resource when the block ends, in reverse order of opening and before any catch or finally runs (Java 7; existing effectively final variables since Java 9).

Examples

  • try (var reader = Files.newBufferedReader(path)) { ... } closes the reader however the block ends.

Read the full section →