public static void main(String[] args) { try (MyClass m = new MyClass()) { m.f(); } catch (Exception e) { e.printStackTrace(); } }