Resource Management in C++: Listing 7

Scope-bound objects in Java.

public class ScopeBoundExample implements java.lang.AutoCloseable {
  public void close()
    System.out.println("Releasing resource.");
  public static void main(String[] args) {
    try (ScopeBoundExample sbe = new ScopeBoundExample())
      System.out.println("Inside the try-with-resources. Exception to be thrown.");
      throw new RuntimeException();

About the Author

Diego Dagum is a software architect and developer with more than 20 years of experience. He can be reached at [email protected].

comments powered by Disqus


Subscribe on YouTube