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

Featured

  • Microsoft's New Programming Language for Excel Now Turing Complete

    Microsoft, which calls its Excel spreadsheet a programming language, reports that an effort called LAMBDA to make it even more of a programming language is paying off, recently being deemed Turing complete.

  • New Visual Studio Razor Editor 'Close to Being Ready' for Blazor and Other Projects

    The experimental Razor editor for Visual Studio introduced last summer has been updated and is "close to being ready for normal daily development."

  • Microsoft Updates 'Must Have' Xamarin Community Toolkit

    The Xamarin Community Toolkit provides all kinds of effects, views and helpers to complement mobile app development with Microsoft's recently released, open source, cross-platform Xamarin.Forms 5.

  • JetBrains Unveils Plans for WinForms, WPF and More in Rider .NET IDE

    JetBrains announced plans for Windows Forms, Windows Presentation Foundation (WPF), ASP.NET and more tooling in the next release of its popular Rider IDE for .NET development.

Upcoming Events