Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Catch exception - begin, rescue

  • begin
  • rescue
filenames = ["README.md", "Other file", "crystal.json"]
filenames.each { |file|
  begin
    result = process(file)
    puts result
  rescue err
    puts "Rescued! #{err.message}"
    puts err.class # File::NotFoundError
  end
}

def process(filename)
  content = File.read(filename)
  return content.size
end