Code Explainers

Code explainers tagged #exception-safety

java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
 

Java try-with-resources and AutoCloseable

try-with-resources autocloseable resource-management
Intermediate 6 steps
ruby
module FileResource
  # Opens a file, yields it to the caller, and guarantees the
  # handle is closed even if the block raises an exception.
  def self.open(path, mode = "r")

Guaranteeing cleanup with begin/ensure in Ruby

resource-management exception-safety blocks
Intermediate 8 steps