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

comments powered by Disqus


.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events